多线程执行有四种方式,最好的方式是第四种
[list]
[*]A extends Thread类,new A(). a.start()
[*]new 一个实现了Runable接口的对象,调用run()方法
[*]Thread t = new Thread(new Runable());调用t.start()
[*]ExecutorService exec = Executors.newCachedThreadPool(); exec.execute( new Runable());
[/list]
具有返回值的线程,需实现Callable接口,而不是Runable接口,并复写call()方法,而不是run()方法,调用executor.submit(new Callable());
[list]
[*]A extends Thread类,new A(). a.start()
[*]new 一个实现了Runable接口的对象,调用run()方法
[*]Thread t = new Thread(new Runable());调用t.start()
[*]ExecutorService exec = Executors.newCachedThreadPool(); exec.execute( new Runable());
[/list]
具有返回值的线程,需实现Callable接口,而不是Runable接口,并复写call()方法,而不是run()方法,调用executor.submit(new Callable());