当前位置:网站首页>Use the thread factory to set the thread name in the thread pool
Use the thread factory to set the thread name in the thread pool
2022-04-23 03:32:00 【I can fix software】
1、 Implement thread factory interface
public class SmsThreadFactory implements ThreadFactory {
// Thread name
private String sendcode;
public SmsThreadFactory(String sendcode) {
this.sendcode=sendcode;
}
@Override
public Thread newThread(Runnable r) {
// TODO Auto-generated method stub
return new Thread(r, this.sendcode );
}
}
2、 Thread pool creation
// Maximum permission 64 Threads Will be enough ~~ Create thread
ThreadPoolExecutor executor=new ThreadPoolExecutor(8, 32, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(32));
3、 Add threads to the thread pool
// Create thread
Thread sms=new Thread(new SmsThread(msgconf));
SmsThreadFactory smsThreadFactory=new SmsThreadFactory("SENCE_CODE="+msgconf.getSendCode());
// Thread factory Set the name
executor.setThreadFactory(smsThreadFactory);
executor.execute(sms);
版权声明
本文为[I can fix software]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220607291176.html
边栏推荐
- 2022 团体程序设计天梯赛 模拟赛 L1-7 矩阵列平移 (20 分)
- Commonly used classes
- JS, bind the event for a label with input, and then bind the stand-alone event in the parent element. The event is executed twice and solved
- L3-011 direct attack Huanglong (30 points)
- MySQL之explain关键字详解
- Unity knowledge points (ugui)
- Variable definition and use
- Flink customizes the application of sink side sinkfunction
- Idea view history [file history and project history]
- Common exceptions
猜你喜欢
QT dynamic translation of Chinese and English languages
Problem a: face recognition
Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD
Database - MySQL -- Navicat import SQL error 1067 - invalid default value for 'paydate‘
打卡:4.22 C语言篇 -(1)初识C语言 - (11)指针
Basic use of Charles
超好用的【通用Excel导入功能】
Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
TCP three handshakes and four waves
Fiddler use
随机推荐
Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
The art of concurrent programming (5): the use of reentrantlock
Several common methods of multithreading
Variable definition and use
Do you really understand hashcode and equals???
Un aperçu des flux d'E / s et des opérations de fichiers de classe de fichiers
2022 团体程序设计天梯赛 模拟赛 1-8 均是素数 (20 分)
Commonly used classes
The query type of MySQL is very inefficient.
Super easy to use [general excel import function]
Unity games and related interview questions
Codeforces round 784 (Div. 4) (AK CF (XD) for the first time)
7-1 introduction to finance
Design and implementation of redis (1): understand data structures and objects
Translation of l1-7 matrix columns in 2022 group programming ladder Simulation Competition (20 points)
Code forces round # 784 (DIV. 4) solution (First AK CF (XD)
C abstract class
PWA I'm here
Mechanical design knowledge point planning
C-11 problem I: find balloon