com.github.houbbbbb.sso.nt.factory.ThreadFactory Maven / Gradle / Ivy
The newest version!
package com.github.houbbbbb.sso.nt.factory;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author: hbw
* @date: 2020/7/13
**/
public class ThreadFactory {
public ThreadPoolExecutor getThread (ItemType itemType) {
String poolName = "no-name";
switch (itemType) {
case SERVER_THREAD: poolName = "nt-server-pool-"; break;
case CLIENT_THREAD: poolName = "nt-client-pool-"; break;
default: break;
}
java.util.concurrent.ThreadFactory factory = new CustomizableThreadFactory(poolName);
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1,
0L, TimeUnit.SECONDS, new LinkedBlockingQueue(), factory);
return executor;
}
}