01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05: package org.jasig.portal.utils.threading;
06:
07: import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory;
08:
09: /**
10: * Implementation of a ThreadFactory that allows you to set the thread
11: * priority.
12: *
13: * @author Scott Battaglia
14: * @version $Revision: 36731 $ $Date: 2006-09-27 11:21:06 -0700 (Wed, 27 Sep 2006) $
15: *
16: */
17: public class PriorityThreadFactory implements ThreadFactory {
18: private final int threadPriority;
19: private final ThreadGroup tg;
20: private final String threadName;
21:
22: public PriorityThreadFactory(int threadPriority,
23: final String threadPoolName, final ThreadGroup parentGroup) {
24: this .threadPriority = threadPriority;
25: threadName = threadPoolName;
26: this .tg = new ThreadGroup(parentGroup, threadPoolName);
27: }
28:
29: public Thread newThread(Runnable runnable) {
30: Thread t = new Thread(tg, runnable);
31: t.setPriority(this .threadPriority);
32: t.setName(threadName + "#" + t.getId());
33: t.setDaemon(true);
34: return t;
35: }
36: }
|