根据sun解释,线程生命周期在java中有以下几种状态:初始(NEW) ,运行(RUNNABLE),阻塞(BLOCKED),等待(WAITING),超时等待(TIMED_WAITING)和终止(TERMINATED)
一、synchronized void start()
start方法是开启一个线程的意思,已经调用start方法后再继续调用start方法会报错(IllegalThreadStateException)
* <p>* The result is that two threads are running concurrently: the
* current thread (which returns from the call to the
* <code>start</code>method) and the other thread (which executes its
* <code>run</code>method).
上面是jdk原注释,启动启程会同时又两个线程工作,当前调用者线程执行从call处到Thread的start0方法,另一个线程时执行它的run方法,我们默认为当调用start方法,就有一个新的线程去执行run方法
上述描述还有一个点,就是调用run方法的时候,虽然新的线程创建好了,但是只是一个就绪状态,只有当它争取到了cpu资源,就会去执行
二、run方法
run方法是Thread类的成员方法,我们创建线程通常有两种方式,当用实现Runnable的形式,开启线程时,它会调用Thread的run方法,
而我们用集成Thread的形式的话,它调用我们重写的run方法,如何我们直接调用run方法的话,就不会创建新的线程
三、interrupted()和isInterrupted()
interrupted是Thread的静态方法,内部实现是当前线程调用isInterrupted方法,而isInterrupted是Thread的实例方法
当前线程被中断后,intrerrupted方法返回true,第二次继续调用会返回false,是因为状态被清理了,既设置为了false
而isInterrupted方法不会清除线程的状态