parent
08f4b877ce
commit
a8cdd37871
@ -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