线程创建
1:implements Runnable 接口
class test implements Runnable(){
test(){};
//重写Runnable的run方法
@override
public void run(){
}
}
@Test
public void test(){
Thread thread1 = new Thread(new Test());
thread1 .start();
}
2:继承类Thread
Class ThreadTest extends Thread(){
ThreadTest(){};
public void run(){
// do some
}
}
@Test
pubic void test(){
Thread thread = new ThreadTest();
thread.start();
}
线程状态:
new:创建状态
Runnable:就绪状态
Running:运行状态
Dead:死亡状态
Blocked:阻塞状态