Java多线程实现的几种方式

1、继承Thread类

2、实现Runnable接口

3、实现Callable接口+Future封装

4、定时器

5、使用Executors提供的ExecutorService
Executors.newCachedThreadPool
Executors.newFixedThreadPool
Executors.newScheduledThreadPool
Executors.newSingleThreadExecutor
Executors.newWorkStealingPool

6、自定义ThreadPoolExecutor+ThreadFactory

7、parallelStream

8、Fork Join
ForkJoinPool
RecursiveTask
RecursiveAction

9、调用本地方法
使用JNI等

Leave a Reply

Your email address will not be published. Required fields are marked *

*