日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ThreadPoolTaskExecutor多线程使用,及线程池配置

發布時間:2025/3/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ThreadPoolTaskExecutor多线程使用,及线程池配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.配置?ThreadPoolTaskExecutor bean

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!-- 掃描注解 --><context:component-scan base-package="com.qi.quartz"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /></context:component-scan><bean id="taskExecutor" name="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <!-- 核心線程數 線程池維護線程的最少數量 --><property name="corePoolSize" value="10" /> <!-- 線程池維護線程所允許的空閑時間 --><property name="keepAliveSeconds" value="200" /> <!-- 線程池維護線程的最大數量 --><property name="maxPoolSize" value="20" /> <!-- 線程池所使用的緩沖隊列 --><property name="queueCapacity" value="100" /> <!-- 線程池對拒絕任務(無線程可用)的處理策略 ThreadPoolExecutor.CallerRunsPolicy策略 ,調用者的線程會執行該任務,如果執行器已關閉,則丟棄. --><property name="rejectedExecutionHandler"><bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" /></property> </bean> </beans>

2.controller使用

package com.qi.quartz.web;import javax.annotation.Resource;import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;@Controller @RequestMapping("/test") public class ThreadPoolExcuteController {Logger LOG = LoggerFactory.getLogger(ThreadPoolExcuteController.class);@Resource(name = "taskExecutor")private ThreadPoolTaskExecutor taskExecutor;@RequestMapping("/execute")@ResponseBodypublic void execute(){taskExecutor.execute(new Runnable(){public void run() {try {LOG.info("執行線程任務開始前");Thread.currentThread().sleep(10000);if (LOG.isDebugEnabled()) {LOG.info("執行線程任務結束");}} catch (InterruptedException e) {e.printStackTrace();}}});}}

3.使用 apache ab 并發測試

/usr/local/apache2/bin/ab?-n 1000 -c 1000 http://192.168.8.101:8080/QuartzDemo/test/execute

Benchmarking 192.168.8.101 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software: Apache-Coyote/1.1
Server Hostname: 192.168.8.101
Server Port: 8080

Document Path: /QuartzDemo/test/execute
Document Length: 3 bytes

Concurrency Level: 1000
Time taken for tests: 41.982 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 163000 bytes
HTML transferred: 3000 bytes
Requests per second: 23.82 [#/sec] (mean)
Time per request: 41982.345 [ms] (mean)
Time per request: 41.982 [ms] (mean, across all concurrent requests)
Transfer rate: 3.79 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 304 211.4 291 1077
Processing: 172 22968 13412.1 21237 41240
Waiting: 161 22900 13455.0 21174 41171
Total: 472 23272 13441.8 21505 41944

Percentage of the requests served within a certain time (ms)
50% 21505
66% 31398
75% 31725
80% 40963
90% 41467
95% 41605
98% 41930
99% 41939
100% 41944 (longest request)

?

我們配置的核心處理10個線程,最大20個,緩沖隊列100,總耗時41.982,隨著我們更改這些配置的時候,處理的情況就不同了。

?

更改配置為

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!-- 掃描注解 --><context:component-scan base-package="com.qi.quartz"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /></context:component-scan><bean id="taskExecutor" name="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <!-- 核心線程數 線程池維護線程的最少數量 --><property name="corePoolSize" value="100" /> <!-- 線程池維護線程所允許的空閑時間 --><property name="keepAliveSeconds" value="200" /> <!-- 線程池維護線程的最大數量 --><property name="maxPoolSize" value="100" /> <!-- 線程池所使用的緩沖隊列 --><property name="queueCapacity" value="500" /> <!-- 線程池對拒絕任務(無線程可用)的處理策略 ThreadPoolExecutor.CallerRunsPolicy策略 ,調用者的線程會執行該任務,如果執行器已關閉,則丟棄. --><property name="rejectedExecutionHandler"><bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" /></property> </bean> </beans>

?

執行測試

./ab -n 1000 -c 1000 http://192.168.8.101:8080/QuartzDemo/test/execute

1000個請求,每次 1000個并發

結果

Server Software: Apache-Coyote/1.1 Server Hostname: 192.168.8.101 Server Port: 8080Document Path: /QuartzDemo/test/execute Document Length: 0 bytesConcurrency Level: 1000 Time taken for tests: 22.452 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 121121 bytes HTML transferred: 0 bytes Requests per second: 44.54 [#/sec] (mean) Time per request: 22452.351 [ms] (mean) Time per request: 22.452 [ms] (mean, across all concurrent requests) Transfer rate: 5.27 [Kbytes/sec] receivedConnection Times (ms)min mean[+/-sd] median max Connect: 1 216 403.0 95 3035 Processing: 210 6209 6834.3 1431 21534 Waiting: 209 6208 6834.3 1431 21534 Total: 334 6425 7071.3 1529 22421Percentage of the requests served within a certain time (ms)50% 152966% 1131875% 1163080% 1183090% 2131595% 2231698% 2233899% 22353100% 22421 (longest request)

?

可以看出僅用了22.452 秒,但是我們的請求數卻高出了很多 ?1000*1000-100*100 = 990000。

當然了,至于開多少個線程,還要看機器如何了。

?

轉載于:https://www.cnblogs.com/yun965861480/p/6517000.html

總結

以上是生活随笔為你收集整理的ThreadPoolTaskExecutor多线程使用,及线程池配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 精人妻一区二区三区 | 自拍偷拍p | 女王脚交玉足榨精调教 | 欧美性受xxxx白人性爽 | 韩产日产国产欧产 | 男女污污软件 | 国产成人a∨| 国产黄色影院 | 森林影视官网在线观看 | 成人午夜一区二区 | 欧美日本一道本 | 亚洲青涩在线 | 亚洲视频在线免费观看 | 日本少妇做爰全过程毛片 | 69精品久久久久久 | 国产精品成人自拍 | 一级片大全| 337p粉嫩日本欧洲亚洲大胆 | 波多野 在线| 免费成人小视频 | 两女双腿交缠激烈磨豆腐 | 91国产丝袜播放在线 | 色综合综合网 | 麻豆视频入口 | av电影中文字幕 | 91涩涩视频| 日本美女视频一区 | 中文字幕在线观看第二页 | 熟女毛毛多熟妇人妻aⅴ在线毛片 | 亚洲精品白浆高清久久久久久 | 91亚洲成人 | av一区免费 | 午夜精品久久久久久久99老熟妇 | 久久久午夜影院 | 成人在线免费高清视频 | 在线看三级 | 51免费看成人啪啪片 | 国产欧美精品在线 | 男人操女人的免费视频 | 久久色av| 午夜影院久久 | 国产片91| www.成人在线观看 | a在线观看视频 | 欧美黑人又粗又大的性格特点 | 国产伦精品一区二区三区高清版禁 | 日韩图片一区 | 欧美a视频 | 国产欧美在线看 | 国产美女无遮挡网站 | 国产一久久 | 日本黄色片网址 | 陪读偷伦初尝小说 | 久久er99热精品一区二区 | 女人脱下裤子让男人桶 | 久久99精品久久久 | 四虎网站在线观看 | 中文字幕久久久久 | av播播 | av看片| 欧美日韩小说 | 国产免费av网址 | 69视频一区| 私库av在线 | 国产又粗又长又大 | 久久特黄视频 | 亚洲男人网站 | 五月婷婷激情在线 | 日日噜噜夜夜狠狠久久丁香五月 | 午夜影视体验区 | 涩涩视频免费观看 | 成年人在线免费 | 91超薄丝袜肉丝一区二区 | 毛片在线看片 | 亚洲天堂网视频 | 色噜噜狠狠一区二区三区牛牛影视 | 日韩一级精品 | www欧美在线 | 亲嘴脱内衣内裤 | 女futa攻玩遍整个后宫 | 毛片久久久久久久 | 黑人精品无码一区二区三区AV | 国产午夜免费 | 一区二区影视 | 香港三级日本三级三69 | 九九热视频在线观看 | 欧美五月婷婷 | 激情爱爱网站 | 日韩av不卡在线播放 | 懂色中文一区二区在线播放 | jiizzyou欧美2 | 麻豆自拍偷拍 | 在线观看精品 | 黄色片子网站 | 亚洲精品国产手机 | 男女男精品视频 | 美女在线网站 | 黄色a一片 | 国产男女猛烈无遮挡免费视频动漫 |