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