public class Thread extends Object implements Runnable
There are two ways to execute code in a new thread. You can either subclass Thread and overriding its run() method, or construct a new Thread and pass a Runnable to the constructor. In either case, the start() method must be called to actually execute the new Thread.
以上是官网对Thread类的使用方法的介绍。即通过继承Thread类并实现run方法,或将Runnable(或实现Runnable接口的类,即实现run方法)实例传递给Thread类的构造器。然后通过调用start()方法开启线程。
我们先来了解下Thread的状态。在java.lang.Thread.State枚举类型中,有BLOCKED(等待被锁)、NEW(已生成实例,但还未未执行)、RUNNABLE(可能在运行) 、TERMINATED(被终止) 、TIMED_WAITING(等待指定的时间) 、WAITING(等待) 等六种状态。