说明直接new 一个 Thread 很占用cpu,所以可以使用线程池
ExecutorService aa = Executors.newCachedThreadPool();
aa.execute(()->{
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(11);
});
aa.execute(()->{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(22);
});
aa.execute(()->{
System.out.println(33);
});
//等待60秒太长,如果有下一次执行,还会很占用内存和cpu,一定要shutdown掉
aa.shutdown();