001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.util.concurrent.ThreadFactory;
018
019
022 public class NamedThreadFactory implements ThreadFactory {
023
024 public NamedThreadFactory(
025 String name, int priority, ClassLoader contextClassLoader) {
026
027 SecurityManager securityManager = System.getSecurityManager();
028
029 if (securityManager != null) {
030 _group = securityManager.getThreadGroup();
031 }
032 else {
033 Thread currentThread = Thread.currentThread();
034
035 _group = currentThread.getThreadGroup();
036 }
037
038 _name = name;
039 _priority = priority;
040 _contextClassLoader = contextClassLoader;
041 }
042
043 public Thread newThread(Runnable runnable) {
044 Thread thread = new Thread(_group, runnable, _name);
045
046 thread.setDaemon(true);
047 thread.setPriority(_priority);
048
049 if (_contextClassLoader != null) {
050 thread.setContextClassLoader(_contextClassLoader);
051 }
052
053 return thread;
054 }
055
056 private ClassLoader _contextClassLoader;
057 private ThreadGroup _group;
058 private String _name;
059 private int _priority;
060
061 }