java 启动多线程

java 平时启动临时的线程  偷懒的做法是

new Thread(new Runnable() {
    @Override
    public void run() {
        
    }
}).start();

 

其实通过线程池会更好。如下两种

ExecutorService threadPool = Executors.newFixedThreadPool(100);
threadPool.execute(new Runnable() {
    @Override
    public void run() {
        
    }
});

 

 

ExecutorService threadPool = Executors.newFixedThreadPool(100);
Runnable runnable =()->{
    //TODO
};
threadPool.submit(runnable);

 

 

posted @ 2019-07-11 22:27  妖君你好  阅读(153)  评论(0编辑  收藏  举报