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