com.eg.agent.android.util.BaseThreadFactory Maven / Gradle / Ivy
The newest version!
package com.eg.agent.android.util;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
public class BaseThreadFactory implements ThreadFactory
{
final ThreadGroup group;
final String namePrefix;
final AtomicInteger threadNumber = new AtomicInteger(1);
public BaseThreadFactory(String factoryName)
{
SecurityManager s = System.getSecurityManager();
this.group = (s != null ? s.getThreadGroup() : Thread.currentThread().getThreadGroup());
this.namePrefix = ("EG_" + factoryName + "-");
}
public Thread newThread(Runnable r)
{
Thread t = new Thread(this.group, r, this.namePrefix + this.threadNumber.getAndIncrement(), 0L);
if (t.isDaemon())
{
t.setDaemon(false);
}
if (t.getPriority() != 5)
{
t.setPriority(5);
} return t;
}
}