一线程的创建
1.继承Thread类
//
public class MyThread extends Thread{
public void run(){
.........
}
}
//Test类
public class Test{
public static void main(String[] args){
MyThread mythread=new MyThread();
mythread.start();
}
}
2.实现runnable接口
public MyThrad1 implements Runnadle{
public void run(){
...
}
}
//Test
public class Test{
public static void main(String[] args){
MyThread1 mythread1=new MyThread1();
Thrad thread=new Thread(mythread1);
thread.start();
}
}
二,线程的周期
1.创建
2.就绪
start()
3.运行
4.阻塞
sleep()
5.死亡
destory()
相关方法:
run(); start(); sleep(); wait(); join(); notify(); notifyAll();