java.lang.Thread.checkAccess()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(236)

本文整理了Java中java.lang.Thread.checkAccess()方法的一些代码示例,展示了Thread.checkAccess()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.checkAccess()方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:checkAccess

Thread.checkAccess介绍

[英]Determines if the currently running thread has permission to modify this thread.

If there is a security manager, its checkAccess method is called with this thread as its argument. This may result in throwing a SecurityException.
[中]确定当前运行的线程是否具有修改此线程的权限。
如果存在安全管理器,则调用其checkAccess方法,并将此线程作为其参数。这可能会导致抛出SecurityException

代码示例

代码示例来源:origin: stackoverflow.com

Thread t1 = new Thread();
t1.checkAccess();  // <--- This is an instance method.

Thread.activeCount(); // <-- This is a static method.

代码示例来源:origin: org.apidesign.bck2brwsr/emul.mini

/**
   * Set the handler invoked when this thread abruptly terminates
   * due to an uncaught exception.
   * <p>A thread can take full control of how it responds to uncaught
   * exceptions by having its uncaught exception handler explicitly set.
   * If no such handler is set then the thread's <tt>ThreadGroup</tt>
   * object acts as its handler.
   * @param eh the object to use as this thread's uncaught exception
   * handler. If <tt>null</tt> then this thread has no explicit handler.
   * @throws  SecurityException  if the current thread is not allowed to
   *          modify this thread.
   * @see #setDefaultUncaughtExceptionHandler
   * @see ThreadGroup#uncaughtException
   * @since 1.5
   */
  public void setUncaughtExceptionHandler(UncaughtExceptionHandler eh) {
    checkAccess();
    uncaughtExceptionHandler = eh;
  }
}

代码示例来源:origin: jtulach/bck2brwsr

/**
   * Set the handler invoked when this thread abruptly terminates
   * due to an uncaught exception.
   * <p>A thread can take full control of how it responds to uncaught
   * exceptions by having its uncaught exception handler explicitly set.
   * If no such handler is set then the thread's <tt>ThreadGroup</tt>
   * object acts as its handler.
   * @param eh the object to use as this thread's uncaught exception
   * handler. If <tt>null</tt> then this thread has no explicit handler.
   * @throws  SecurityException  if the current thread is not allowed to
   *          modify this thread.
   * @see #setDefaultUncaughtExceptionHandler
   * @see ThreadGroup#uncaughtException
   * @since 1.5
   */
  public void setUncaughtExceptionHandler(UncaughtExceptionHandler eh) {
    checkAccess();
    uncaughtExceptionHandler = eh;
  }
}

代码示例来源:origin: Hive2Hive/Hive2Hive

public void stopQueueWorker() {
  if (!running.get()) {
    logger.warn("The user profile manager has already been shutdown");
    return;
  }
  running.set(false);
  try {
    // interrupt the thread such that blocking 'wait' calls throw an exception and the thread can
    // shutdown gracefully
    workerThread.checkAccess();
    workerThread.interrupt();
  } catch (SecurityException e) {
    logger.warn("Cannot stop the user profile thread", e);
  }
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul.mini

/**
 * Resumes a suspended thread.
 * <p>
 * First, the <code>checkAccess</code> method of this thread is called
 * with no arguments. This may result in throwing a
 * <code>SecurityException</code> (in the current thread).
 * <p>
 * If the thread is alive but suspended, it is resumed and is
 * permitted to make progress in its execution.
 *
 * @exception  SecurityException  if the current thread cannot modify this
 *               thread.
 * @see        #checkAccess
 * @see        #suspend()
 * @deprecated This method exists solely for use with {@link #suspend},
 *     which has been deprecated because it is deadlock-prone.
 *     For more information, see
 *     <a href="{@docRoot}/../technotes/guides/concurrency/threadPrimitiveDeprecation.html">Why
 *     are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
 */
@Deprecated
public final void resume() {
  checkAccess();
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul.mini

/**
 * Suspends this thread.
 * <p>
 * First, the <code>checkAccess</code> method of this thread is called
 * with no arguments. This may result in throwing a
 * <code>SecurityException </code>(in the current thread).
 * <p>
 * If the thread is alive, it is suspended and makes no further
 * progress unless and until it is resumed.
 *
 * @exception  SecurityException  if the current thread cannot modify
 *               this thread.
 * @see #checkAccess
 * @deprecated   This method has been deprecated, as it is
 *   inherently deadlock-prone.  If the target thread holds a lock on the
 *   monitor protecting a critical system resource when it is suspended, no
 *   thread can access this resource until the target thread is resumed. If
 *   the thread that would resume the target thread attempts to lock this
 *   monitor prior to calling <code>resume</code>, deadlock results.  Such
 *   deadlocks typically manifest themselves as "frozen" processes.
 *   For more information, see
 *   <a href="{@docRoot}/../technotes/guides/concurrency/threadPrimitiveDeprecation.html">Why
 *   are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
 */
@Deprecated
public final void suspend() {
  checkAccess();
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Resumes a suspended thread.
 * <p>
 * First, the <code>checkAccess</code> method of this thread is called
 * with no arguments. This may result in throwing a
 * <code>SecurityException</code> (in the current thread).
 * <p>
 * If the thread is alive but suspended, it is resumed and is
 * permitted to make progress in its execution.
 *
 * @exception  SecurityException  if the current thread cannot modify this
 *               thread.
 * @see        #checkAccess
 * @see        #suspend()
 * @deprecated This method exists solely for use with {@link #suspend},
 *     which has been deprecated because it is deadlock-prone.
 *     For more information, see
 *     <a href="{@docRoot}/../technotes/guides/concurrency/threadPrimitiveDeprecation.html">Why
 *     are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
 */
@Deprecated
public final void resume() {
  checkAccess();
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Suspends this thread.
 * <p>
 * First, the <code>checkAccess</code> method of this thread is called
 * with no arguments. This may result in throwing a
 * <code>SecurityException </code>(in the current thread).
 * <p>
 * If the thread is alive, it is suspended and makes no further
 * progress unless and until it is resumed.
 *
 * @exception  SecurityException  if the current thread cannot modify
 *               this thread.
 * @see #checkAccess
 * @deprecated   This method has been deprecated, as it is
 *   inherently deadlock-prone.  If the target thread holds a lock on the
 *   monitor protecting a critical system resource when it is suspended, no
 *   thread can access this resource until the target thread is resumed. If
 *   the thread that would resume the target thread attempts to lock this
 *   monitor prior to calling <code>resume</code>, deadlock results.  Such
 *   deadlocks typically manifest themselves as "frozen" processes.
 *   For more information, see
 *   <a href="{@docRoot}/../technotes/guides/concurrency/threadPrimitiveDeprecation.html">Why
 *   are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>.
 */
@Deprecated
public final void suspend() {
  checkAccess();
}

相关文章