|
|
package com.yohoufo.order.service.proxy;
|
|
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
|
* 自定义java api线程池内工作线程工厂
|
|
|
* 指定生成线程名称:pool-javaApi-thread-[num]
|
|
|
*/
|
|
|
public class InBoxThreadFactory implements ThreadFactory {
|
|
|
|
|
|
private static final AtomicInteger poolNumber = new AtomicInteger(1);
|
|
|
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
|
|
private final String namePrefix;
|
|
|
private final ThreadGroup group;
|
|
|
|
|
|
public InBoxThreadFactory() {
|
|
|
SecurityManager s = System.getSecurityManager();
|
|
|
group = (s != null) ? s.getThreadGroup() :
|
|
|
Thread.currentThread().getThreadGroup();
|
|
|
namePrefix = "pool-inboxFacade-processor-" +
|
|
|
poolNumber.getAndIncrement() +
|
|
|
"-thread-";
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public Thread newThread(Runnable r) {
|
|
|
Thread t = new Thread(group, r,
|
|
|
namePrefix + threadNumber.getAndIncrement(),
|
|
|
0);
|
|
|
if (t.isDaemon())
|
|
|
t.setDaemon(true);
|
|
|
if (t.getPriority() != Thread.NORM_PRIORITY)
|
|
|
t.setPriority(Thread.NORM_PRIORITY);
|
|
|
return t;
|
|
|
}
|
|
|
} |
...
|
...
|
|