Java???????
???????????? ???????[ 2015/10/21 14:08:28 ] ??????????????????? ???????
????????????????Moore’s law?????????·????????????????????????????????????????????????????????? CPU ???????????????????????????????????????????????????С?????????????????????????????????????????????????????????????????????????紦???? AMD FX-9590 ?????????5 GHz???????????????????????????????????????????????multi-core processors???????4??????????????????飬?????????????????????????????????ò??????????????????????????????????????????????????????????? CPU??
????????
?????????????????????????????????????????????????????? CPU ??????????????? JVM ????????????64λ JVM ??????????С1 MB????????????????????????С?????????????????????????????????????????????????????????????????????????????????????楨CPU???????????£???????????????????????????????????????????????к??????????????????и????????????磬????????denial-of-service?????????????????????????У????????????????thread starvation???????????????????????????????????????????????????????????????????????
??????????????????????????????????????? Tomcat??Undertow??????web???????????????????????????????????????ι???????????????????????????????а?????
???????????????????? Executors ????????????????JDK ????? ExecutorService ?????У?
????ForkJoinPool
????ThreadPoolExecutor
????ScheduledThreadPoolExecutor
??????Щ?????????????????????С?????????? ExecutorService ???????????
????public List<Future<T>> executeTasks(Collection<Callable<T>> tasks) {
????// create an ExecutorService
????// ???? ExecutorService
????final ExecutorService executorService = Executors.newSingleThreadExecutor();
????// execute all tasks
????// ???????????
????final List<Future<T>> executedTasks = executorService.invokeAll(tasks);
????// shutdown the ExecutorService after all tasks have completed
????// ???????????????? ExecutorService
????executorService.shutdown();
????return executedTasks;
????}
???????????????????? ExecutorService —— ????????????????executor???????????????????????е??????????????????????????????? ExecutorService????????? Executors ??????????????? ExecutorService??
????newCachedThreadPool() ????????? ExecutorService???? ExecutorService ??????????????????????????????????????????????
????newFixedThreadPool(int numberOfThreads) ??????????????????????????????? ExecutorService??
????newScheduledThreadPool(int corePoolSize)????????????????????????? ExecutorService???????????????? ExecutorService????
????newSingleThreadExecutor()????????????????? ExecutorService??
????newSingleThreadScheduledExecutor()???????????????????????????? ExecutorService????????????????????
????newWorkStealingPool()???????????ж????????У????????????????? ExecutorService??
??????????????????????е???????????Σ????????????????????????????
????void execute(Runnable)
????Future submit(Callable)
????Future submit(Runnable)
????????? executorService??Shutdown() ??????????????????????÷?????ExecutorService ????“???????shutdown mode??”????????£???????????????????????????????μ???????????????????????????????? awaitTermination() ??????
????ExecutorService ??????????????????????????????????????е???????????????????????????????????????????????????????? ExecutorService ?????????????????????ExecutorService ?????????????????????????????????????????????????????棬????????????????????????е?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????δ??????????——Future????????? Java 8?У?????????????? CompletableFuture????ν???? Future ???? CompletableFuture ??????????????????Χ???????????????????????????? Callable ???Future ???????壬??? Callable ???????????? Runnable ??С?
??????????
???????????????????????
?????????????У?
???????????????????
???????????????
?????????????????????
????ExecutorService ????к?????????????????3???? ThreadPoolExecutor????????newCachedThreadPool()??newFixedThreadPool() ?? newSingleThreadExecutor() ???????????????? ThreadPoolExecutor ??????????????????????ThreadPoolExecutor ???????????????5????????
????int corePoolSize???????????????????
????int maximumPoolSize?????????????
????long keepAlive and TimeUnit unit?????? corePoolSize ??С???????е??????????????????
????BlockingQueue workQueue???????????????????????е????С?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11