Coverage Report - org.mule.module.launcher.ConfigChangeMonitorThreadFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigChangeMonitorThreadFactory
0%
0/14
0%
0/6
2
 
 1  
 /*
 2  
  * $Id: ConfigChangeMonitorThreadFactory.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  
 /**
 17  
  * A slightly tweaked default thread factory that uses the following pattern:
 18  
  * <code>[%s].config.change.%d.thread.%d</code>, where %s stands for application name,
 19  
  * the next number will tell one how many redeployments this app had during this container's
 20  
  * lifetime and the last digit, thread count, should always be 1. Left there for debugging
 21  
  * purposes to quickly locate any duplicate threads trying to perform a redeploy. 
 22  
  */
 23  
 public class ConfigChangeMonitorThreadFactory implements ThreadFactory
 24  
 {
 25  
 
 26  0
     static final AtomicInteger poolNumber = new AtomicInteger(1);
 27  
     final ThreadGroup group;
 28  0
     final AtomicInteger threadNumber = new AtomicInteger(1);
 29  
     final String namePrefix;
 30  
     final String appName;
 31  
 
 32  
     public ConfigChangeMonitorThreadFactory(String appName)
 33  0
     {
 34  0
         this.appName = appName;
 35  0
         SecurityManager s = System.getSecurityManager();
 36  0
         group = (s != null) ? s.getThreadGroup() :
 37  
                 Thread.currentThread().getThreadGroup();
 38  0
         namePrefix = String.format("[%s].config.change.%d.thread.", appName, poolNumber.getAndIncrement());
 39  0
     }
 40  
 
 41  
     public Thread newThread(Runnable r)
 42  
     {
 43  0
         Thread t = new Thread(group, r,
 44  
                               namePrefix + threadNumber.getAndIncrement(),
 45  
                               0);
 46  0
         if (t.isDaemon())
 47  
         {
 48  0
             t.setDaemon(false);
 49  
         }
 50  0
         if (t.getPriority() != Thread.NORM_PRIORITY)
 51  
         {
 52  0
             t.setPriority(Thread.NORM_PRIORITY);
 53  
         }
 54  0
         return t;
 55  
     }
 56  
 
 57  
 
 58  
 }