1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util.concurrent; |
12 | |
|
13 | |
import org.mule.util.StringUtils; |
14 | |
|
15 | |
import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory; |
16 | |
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong; |
17 | |
|
18 | |
public class NamedThreadFactory implements ThreadFactory |
19 | |
{ |
20 | |
private final String name; |
21 | |
private final AtomicLong counter; |
22 | |
|
23 | |
public NamedThreadFactory(String name) |
24 | 0 | { |
25 | 0 | if (StringUtils.isEmpty(name)) |
26 | |
{ |
27 | 0 | throw new IllegalArgumentException("NamedThreadFactory must have a proper name."); |
28 | |
} |
29 | |
|
30 | 0 | this.name = name; |
31 | 0 | this.counter = new AtomicLong(1); |
32 | 0 | } |
33 | |
|
34 | |
public Thread newThread(Runnable runnable) |
35 | |
{ |
36 | 0 | Thread t = new Thread(runnable, name + '.' + counter.getAndIncrement()); |
37 | 0 | return t; |
38 | |
} |
39 | |
|
40 | |
} |