Created
August 21, 2019 08:59
-
-
Save codethereforam/29677c54f314066ef90d33fe75bc1107 to your computer and use it in GitHub Desktop.
提供一些构造spring的ThreadPoolTaskExecutor的静态工厂方法,模仿JDK中的Executors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 提供一些构造spring的ThreadPoolTaskExecutor的静态工厂方法,模仿JDK中的Executors | |
* | |
* @author yanganyu | |
* @date 2019/8/21 16:23 | |
*/ | |
public class SpringExecutors { | |
private SpringExecutors() { | |
} | |
/** | |
* 等价于{@code Executors.newSingleThreadExecutor} | |
* | |
* @param threadNamePrefix thread name prefix | |
* @return ThreadPoolTaskExecutor | |
*/ | |
public static ThreadPoolTaskExecutor newSingleThreadExecutor(String threadNamePrefix) { | |
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | |
executor.setThreadNamePrefix(threadNamePrefix); | |
executor.setCorePoolSize(1); | |
executor.setMaxPoolSize(1); | |
executor.setKeepAliveSeconds(0); | |
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy()); | |
return executor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment