Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.penglecode.common.support;
 
named thread factory

Author(s):
pengpeng
Version:
1.0
Date:
2014年5月22日 上午10:04:43
public class NamedThreadFactory implements ThreadFactory {
	public static final String DEFAULT_THREAD_NAME_PREFIX = "threadPool";
	private static final AtomicInteger threadPoolNumber = new AtomicInteger(1);
	private final ThreadGroup group;
	private final AtomicInteger threadNumber = new AtomicInteger(1);
	private final String NAME_PATTERN = "%s-%d-thread";
	private final String threadNamePrefix;
	public NamedThreadFactory(String threadNamePrefix) {
		super();
		final SecurityManager sm = System.getSecurityManager();
		this. = (sm != null) ? sm.getThreadGroup() : Thread.currentThread().getThreadGroup();
	}
	public String checkThreadNamePrefix(String threadNamePrefix) {
		if(threadNamePrefix == null || "".equals(threadNamePrefix.trim())){
		}
		return threadNamePrefix;
	}
	public Thread newThread(Runnable r) {
		final Thread thread = new Thread(r, String.format("%s-%d".getAndIncrement()), 0);
		thread.setDaemon(false);
		return thread;
	}
New to GrepCode? Check out our FAQ X