JavaTM 2 Platform
Standard Ed. 5.0

类 java.lang.Thread
的使用

使用 Thread 的软件包
java.lang 提供利用 Java 编程语言进行程序设计的基础类。 
java.util.concurrent 在并发编程中很常用的实用工具类。 
java.util.concurrent.locks 为锁定和等待条件提供一个框架的接口和类,它不同于内置同步和监视器。 
javax.swing.text 提供类 HTMLEditorKit 和创建 HTML 文本编辑器的支持类。 
 

java.lang 中 Thread 的使用
 

返回 Thread 的 java.lang 中的方法
static Thread Thread.currentThread()
          返回对当前正在执行的线程对象的引用。
 

返回变量类型为 Thread 的类型的 java.lang 中的方法
static Map<Thread,StackTraceElement[]> Thread.getAllStackTraces()
          返回所有活动线程的堆栈跟踪的一个映射。
 

参数类型为 Thread 的 java.lang 中的方法
 void Runtime.addShutdownHook(Thread hook)
          注册新的虚拟机来关闭挂钩。
 void SecurityManager.checkAccess(Thread t)
          如果不允许调用线程修改 thread 参数,则抛出 SecurityException。
static int Thread.enumerate(Thread[] tarray)
          将当前线程的线程组及其子组中的每一个活动线程复制到指定的数组中。
 int ThreadGroup.enumerate(Thread[] list)
          把此线程组及其子组中的所有活动线程复制到指定数组中。
 int ThreadGroup.enumerate(Thread[] list, boolean recurse)
          把此线程组中的所有活动线程复制到指定数组中。
 boolean Runtime.removeShutdownHook(Thread hook)
          取消注册某个先前已注册的虚拟机关闭挂钩。
 void Thread.UncaughtExceptionHandler.uncaughtException(Thread t, Throwable e)
          当给定线程因给定的未捕获异常而终止时,调用该方法。
 void ThreadGroup.uncaughtException(Thread t, Throwable e)
          当此线程组中的线程因为一个未捕获的异常而停止,并且线程没有安装特定 Thread.UncaughtExceptionHandler 时,由 Java Virtual Machine 调用此方法。
 

java.util.concurrent 中 Thread 的使用
 

返回 Thread 的 java.util.concurrent 中的方法
 Thread ThreadFactory.newThread(Runnable r)
          构造一个新 Thread。
 

返回变量类型为 Thread 的类型的 java.util.concurrent 中的方法
protected  Collection<Thread> Semaphore.getQueuedThreads()
          返回一个 collection,包含可能等待获取的线程。
 

参数类型为 Thread 的 java.util.concurrent 中的方法
protected  void ThreadPoolExecutor.beforeExecute(Thread t, Runnable r)
          在执行给定线程中的给定 Runnable 之前调用的方法。
 void TimeUnit.timedJoin(Thread thread, long timeout)
          使用此时间单元执行计时的 Thread.join。
 

java.util.concurrent.locks 中 Thread 的使用
 

返回 Thread 的 java.util.concurrent.locks 中的方法
 Thread AbstractQueuedSynchronizer.getFirstQueuedThread()
          返回队列中第一个(等待时间最长的)线程,如果目前没有将任何线程加入队列,则返回 null。
protected  Thread ReentrantLock.getOwner()
          返回目前拥有此锁定的线程,如果此锁定不被任何线程拥有,则返回 null。
protected  Thread ReentrantReadWriteLock.getOwner()
          返回当前拥有写入锁定的线程,如果没有这样的线程,则返回 null。
 

返回变量类型为 Thread 的类型的 java.util.concurrent.locks 中的方法
 Collection<Thread> AbstractQueuedSynchronizer.getExclusiveQueuedThreads()
          返回包含可能正以独占模式等待获取的线程 collection。
protected  Collection<Thread> ReentrantReadWriteLock.getQueuedReaderThreads()
          返回一个 collection,它包含可能正在等待获取读取锁定的线程。
protected  Collection<Thread> ReentrantLock.getQueuedThreads()
          返回一个 collection,它包含可能正等待获取此锁定的线程。
 Collection<Thread> AbstractQueuedSynchronizer.getQueuedThreads()
          返回包含可能正在等待获取的线程 collection。
protected  Collection<Thread> ReentrantReadWriteLock.getQueuedThreads()
          返回一个 collection,它包含可能正在等待获取读取或写入锁定的线程。
protected  Collection<Thread> ReentrantReadWriteLock.getQueuedWriterThreads()
          返回一个 collection,它包含可能正在等待获取写入锁定的线程。
 Collection<Thread> AbstractQueuedSynchronizer.getSharedQueuedThreads()
          返回包含可能正以共享模式等待获取的线程 collection。
protected  Collection<Thread> AbstractQueuedSynchronizer.ConditionObject.getWaitingThreads()
          返回包含那些可能正在等待此条件的线程 collection。
 Collection<Thread> AbstractQueuedSynchronizer.getWaitingThreads(AbstractQueuedSynchronizer.ConditionObject condition)
          返回一个 collection,其中包含可能正在等待与此同步器有关的给定条件的那些线程。
protected  Collection<Thread> ReentrantLock.getWaitingThreads(Condition condition)
          返回一个 collection,它包含可能正在等待与此锁定相关给定条件的那些线程。
protected  Collection<Thread> ReentrantReadWriteLock.getWaitingThreads(Condition condition)
          返回一个 collection,它包含可能正在等待与写入锁定相关的给定条件的那些线程。
 

参数类型为 Thread 的 java.util.concurrent.locks 中的方法
 boolean ReentrantLock.hasQueuedThread(Thread thread)
          查询给定线程是否正在等待获取此锁定。
 boolean ReentrantReadWriteLock.hasQueuedThread(Thread thread)
          查询是否给定线程正在等待获取读取或写入锁定。
 boolean AbstractQueuedSynchronizer.isQueued(Thread thread)
          如果给定线程目前已加入队列,则返回 true。
static void LockSupport.unpark(Thread thread)
          如果给定线程的许可尚不可用,则使其可用。
 

javax.swing.text 中 Thread 的使用
 

返回 Thread 的 javax.swing.text 中的方法
protected  Thread AbstractDocument.getCurrentWriter()
          获取当前的写入线程(如果有的话)。
 


JavaTM 2 Platform
Standard Ed. 5.0

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。