com.aliyun.dts.subscribe.clients.common.ThreadFactoryWithNamePrefix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dts-new-subscribe-sdk Show documentation
Show all versions of dts-new-subscribe-sdk Show documentation
The Aliyun new Subscribe SDK for Java used for accessing Data Transmission Service
The newest version!
package com.aliyun.dts.subscribe.clients.common;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadFactoryWithNamePrefix implements ThreadFactory {
private static final AtomicInteger POOL_NUMBER = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
private final boolean daemon;
public ThreadFactoryWithNamePrefix(String poolPrefix) {
this(poolPrefix, false);
}
public ThreadFactoryWithNamePrefix(String poolPrefix, boolean daemon) {
this.daemon = daemon;
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
namePrefix = poolPrefix + POOL_NUMBER.getAndIncrement() + "-thread-";
}
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(group, r,
namePrefix + threadNumber.getAndIncrement(),
0);
t.setDaemon(daemon);
if (t.getPriority() != Thread.NORM_PRIORITY) {
t.setPriority(Thread.NORM_PRIORITY);
}
return t;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy