1 10 11 package org.mule.util.concurrent; 12 13 import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory; 14 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong; 15 16 import org.apache.commons.lang.StringUtils; 17 18 public class NamedThreadFactory implements ThreadFactory 19 { 20 private final String name; 21 private final int priority; 22 private final AtomicLong counter; 23 24 public NamedThreadFactory(String name) 25 { 26 this(name, Thread.NORM_PRIORITY); 27 } 28 29 public NamedThreadFactory(String name, int priority) 30 { 31 if (StringUtils.isEmpty(name)) 32 { 33 throw new IllegalArgumentException ("NamedThreadFactory must have a proper name."); 34 } 35 36 this.name = name; 37 this.priority = priority; 38 this.counter = new AtomicLong(1); 39 } 40 41 public Thread newThread(Runnable runnable) 42 { 43 Thread t = new Thread (runnable, name + '.' + counter.getAndIncrement()); 44 t.setPriority(priority); 45 return t; 46 } 47 48 } 49 | Popular Tags |