1
14
15 package com.liferay.portal.kernel.util;
16
17 import java.util.concurrent.ThreadFactory;
18
19
24 public class NamedThreadFactory implements ThreadFactory {
25
26 public NamedThreadFactory(
27 String name, int priority, ClassLoader contextClassLoader) {
28
29 SecurityManager securityManager = System.getSecurityManager();
30
31 if (securityManager != null) {
32 _group = securityManager.getThreadGroup();
33 }
34 else {
35 Thread currentThread = Thread.currentThread();
36
37 _group = currentThread.getThreadGroup();
38 }
39
40 _name = name;
41 _priority = priority;
42 _contextClassLoader = contextClassLoader;
43 }
44
45 public Thread newThread(Runnable runnable) {
46 Thread thread = new Thread(_group, runnable, _name);
47
48 thread.setDaemon(true);
49 thread.setPriority(_priority);
50
51 if (_contextClassLoader != null) {
52 thread.setContextClassLoader(_contextClassLoader);
53 }
54
55 return thread;
56 }
57
58 private ClassLoader _contextClassLoader;
59 private ThreadGroup _group;
60 private String _name;
61 private int _priority;
62
63 }