View Javadoc

1   /*
2    * $Id: AppDeployerMonitorThreadFactory.java 20088 2010-11-05 16:51:41Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.launcher;
12  
13  import java.util.concurrent.ThreadFactory;
14  import java.util.concurrent.atomic.AtomicInteger;
15  
16  public class AppDeployerMonitorThreadFactory implements ThreadFactory
17  {
18  
19      static final AtomicInteger poolNumber = new AtomicInteger(1);
20      final ThreadGroup group;
21      final AtomicInteger threadNumber = new AtomicInteger(1);
22      final String namePrefix;
23  
24      public AppDeployerMonitorThreadFactory()
25      {
26          SecurityManager s = System.getSecurityManager();
27          group = (s != null) ? s.getThreadGroup() :
28                  Thread.currentThread().getThreadGroup();
29          namePrefix = String.format("app-deployer-monitor-%d-thread-",  poolNumber.getAndIncrement());
30      }
31  
32      public Thread newThread(Runnable r)
33      {
34          Thread t = new Thread(group, r,
35                                namePrefix + threadNumber.getAndIncrement(),
36                                0);
37          // make sure it's non-daemon, allows for an 'idle' state of Mule by preventing early termination
38          t.setDaemon(false);
39          t.setPriority(Thread.MIN_PRIORITY);
40          return t;
41      }
42  
43  
44  }