JAvaの高度な特性-スレッド1
6324 ワード
1、 : new born
2、 start : ready( )
3、CPU running blocked(sleep/wait(0)-> notify)
,
4、run : dead( : )
a、
Thread thread = new Thread(){
@overridee
Public void run(){
....}
};
Thread.start()
b、 Thread
Class MyThread extends Thread{
//
...
//
...
@override
Public void run(){
....}
}
Thread thread = new MyThread ();
Thread.start();
c、 Runable
Class MyRun implents Runable{
@overridePublic
void run(){}
}
Runable mr= new MyRun ();
Thread thread = new Thread(mr);
Thread.start();
d、 // :
public class MyCall implements Callable<T>{
//
//
@override
Public T call(){
...
}
}
Mycall mc = new Mycall(...);
Future<T> fu = esf.submit(mc);
T t = fu.get();