Pre Merge pull request !384 from imalasong/pr/1
commit
2255bbda98
@ -0,0 +1,31 @@
|
|||||||
|
package com.ruoyi.common.core.executor;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程工厂
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class ThreadFactoryImpl implements ThreadFactory {
|
||||||
|
private final AtomicLong threadIndex = new AtomicLong(0);
|
||||||
|
private final String threadNamePrefix;
|
||||||
|
private final boolean daemon;
|
||||||
|
|
||||||
|
public ThreadFactoryImpl(final String threadNamePrefix) {
|
||||||
|
this(threadNamePrefix, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ThreadFactoryImpl(final String threadNamePrefix, boolean daemon) {
|
||||||
|
this.threadNamePrefix = threadNamePrefix;
|
||||||
|
this.daemon = daemon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable r) {
|
||||||
|
Thread thread = new Thread(r, threadNamePrefix + this.threadIndex.incrementAndGet());
|
||||||
|
thread.setDaemon(daemon);
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue