How many ways are for creating a new thread in Java?

后端 未结 7 2166
清歌不尽
清歌不尽 2020-12-29 10:14

Actually, what other ways are available apart from extending the Thread class and implementing the Runnable interface?

7条回答
  •  醉话见心
    2020-12-29 10:43

    The preferred way of starting threads in Java 6 is using Executors:

        ExecutorService es = Executors.newCachedThreadPool();
        Runnable r = ;
        es.execute(r);
    

提交回复
热议问题