9.3.1 Thread 类成员变量及方法
1、Thread 类的构造函数有下面几种形式。
public Thread()
public Thread(Runnable target) //当线程启动时,它将激发 target 中的 run()方法;
public Thread(ThreadGroup group, String name) //当创建该线程时,可以将该线程
加入到不同的线程组 group 中;
public Thread(String name) //线程名,利用线程名可以将不同的线程区分开来,
也可以用 null 作为线程名。
public Thread(ThreadGroup group, Runnable target)
public Thread(ThreadGroup group, Runnable targer, String name)
Thread 类具有下面的一系列方法来控制线程。
public static native Thread currentThread() //返回当前活动线程的引用;
public static native void yield() //使当前执行线程暂时停止执行而让其他线程执行;
public static native void sleep(long millis) throws InterruptedException //使当前
活动线程睡眠指定的时间 millisms;
public static void sleep(long millis,int nanos)throws InterruptedException //使当前
活动线程睡眠指定的时间 millisms 加上十万分之 nanos 秒;
public native synchronized void start() //开始运行当前线程;
public void run() //如果当前线 程 是 用 一 个 单 独 Runnable 接 口 构 造 的 , 则 实 现 该
Runnable 接口的 run 方法,否则什么都不做并且返回;
public final void stop() //强制当前线程停止运行,并抛出 ThreadDead 错误;
public final synchronized void stop(Throwable o) //强制当前线程停止运行,但抛出
一个 Throwable 对象而不是 ThreadDead 错误;
public static boolean interupted() //测试当前线程是否被中断;
public boolean isInterrupted() //测试当前线程是否被中断;
public void destroy() //撤消当前线程;
public final native boolean isAlive() //测试当前线程是否在活动;
public final void suspend() //临时挂起当前线程;
public final void resume() //恢复运行挂起的线程;