94 |
brianR |
1 |
/*
|
|
|
2 |
* Copyright 2012 Brian Rosenberger (Brutex Network)
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
package net.brutex.xservices.util.cache;
|
|
|
18 |
|
|
|
19 |
import java.util.concurrent.Executors;
|
|
|
20 |
import java.util.concurrent.ThreadFactory;
|
|
|
21 |
|
|
|
22 |
public class DaemonThreadFactory implements ThreadFactory {
|
|
|
23 |
|
|
|
24 |
private final ThreadFactory factory;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Construct a ThreadFactory with setDeamon(true) using
|
|
|
28 |
* Executors.defaultThreadFactory()
|
|
|
29 |
*/
|
|
|
30 |
public DaemonThreadFactory() {
|
|
|
31 |
this(Executors.defaultThreadFactory());
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Construct a ThreadFactory with setDeamon(true) wrapping the given factory
|
|
|
36 |
*
|
|
|
37 |
* @param thread
|
|
|
38 |
* factory to wrap
|
|
|
39 |
*/
|
|
|
40 |
public DaemonThreadFactory(ThreadFactory factory) {
|
|
|
41 |
if (factory == null)
|
|
|
42 |
throw new NullPointerException("factory cannot be null");
|
|
|
43 |
this.factory = factory;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public Thread newThread(Runnable r) {
|
|
|
47 |
final Thread t = factory.newThread(r);
|
|
|
48 |
t.setDaemon(true);
|
|
|
49 |
return t;
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|