当前位置:网站首页>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
边栏推荐
- Do you really understand hashcode and equals???
- Three types of jump statements
- Development record of primary sensitive word detection
- Visual programming -- how to customize the mouse cursor
- Three column layout (fixed width on both sides in the middle and fixed width on both sides in the middle)
- Identifier and type conversion
- Punch in: 4.22 C language chapter - (1) first knowledge of C language - (11) pointer
- 你真的懂hashCode和equals吗???
- PYMOL-note
- Several common methods of multithreading
猜你喜欢

Section 2 map and structure in Chapter 6

Code forces round # 784 (DIV. 4) solution (First AK CF (XD)

Codeforces Round #784 (Div. 4)题解 (第一次AK cf (XD

Unity Basics

Visual programming -- how to customize the mouse cursor

Database SQL -- simulate inserting a large amount of data, importing / exporting database scripts, timestamp conversion and database basics

Design and implementation of redis (5): master-slave replication strategy and optimization

Visual programming - Experiment 1

Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD

Unity basics 2
随机推荐
File upload vulnerability summary and upload labs shooting range documentary
Section 1 array and slicing in Chapter 6
The content of the website is prohibited from copying, pasting and saving as JS code
Codeforces round 784 (Div. 4) (AK CF (XD) for the first time)
Unity basics 2
Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
MySQL query specifies that a row is sorted to the first row
The art of concurrent programming (2): synchronized usage scenarios
ThreadLocal 测试多线程变量实例
Punch in: 4.23 C language chapter - (1) first knowledge of C language - (12) structure
Application and definition of interface
Super easy to use [general excel import function]
Explication détaillée des fonctions send () et recv () du programme Socket
you need to be root to perform this command
Design and implementation of redis (3): persistence strategy RDB, AOF
Téléchargement en vrac de fichiers - téléchargement après compression
Three types of cyclic structure
Design and implementation of redis (5): master-slave replication strategy and optimization
Chapter 8 exception handling, string handling and file operation
Commonly used classes