多线程简单使用
@RequestMapping("/f03")
public void threads(){
System.out.println("----00000000-----");
new Thread(new Runnable() {
public void run() {
try {
System.out.println("----你大爷-----");
} catch (Exception e) {
throw new RuntimeException(e);
}finally{
}
}
}).start();
System.out.println("----11111111-----");
Callable<String> task=new Callable<String>() {
public String call() throws Exception {
return "----你大爷还是你大爷----";
}
};
FutureTask<String> task1 = new FutureTask<String>(task);
ExecutorService excutor=Executors.newCachedThreadPool();
excutor.submit(task1);
try {
System.out.println("----11111111-----"+task1.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}