Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
10 |
* |
11 |
* Unless required by applicable law or agreed to in writing, software |
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
* See the License for the specific language governing permissions and |
15 |
* limitations under the License. |
16 |
*/ |
17 |
package org.apache.tomcat.util.threads; |
18 |
|
19 |
/** |
20 |
* @author pidster |
21 |
* |
22 |
*/ |
23 |
public class TaskThread extends Thread { |
24 |
|
25 |
private long created; |
26 |
|
27 |
/** |
28 |
* @param group |
29 |
* @param target |
30 |
* @param name |
31 |
*/ |
32 |
public TaskThread(ThreadGroup group, Runnable target, String name) { |
33 |
super(group, target, name); |
34 |
this.created = System.currentTimeMillis(); |
35 |
} |
36 |
|
37 |
/** |
38 |
* @param group |
39 |
* @param target |
40 |
* @param name |
41 |
* @param stackSize |
42 |
*/ |
43 |
public TaskThread(ThreadGroup group, Runnable target, String name, long stackSize) { |
44 |
super(group, target, name, stackSize); |
45 |
this.created = System.currentTimeMillis(); |
46 |
} |
47 |
|
48 |
/** |
49 |
* @return the created |
50 |
*/ |
51 |
public final long getCreated() { |
52 |
return created; |
53 |
} |
54 |
|
55 |
/** |
56 |
* @param comparison |
57 |
* @return |
58 |
*/ |
59 |
public boolean isOlderThan(long comparison) { |
60 |
return created < comparison; |
61 |
} |
62 |
|
63 |
/** |
64 |
* @param threadTerminationTimeout |
65 |
*/ |
66 |
public void selfDestruct(long threadTerminationTimeout) { |
67 |
|
68 |
// TODO maybe unset the classloader |
69 |
// TODO maybe clear out the threadLocals |
70 |
// TODO maybe perform additional cleanup |
71 |
|
72 |
try { |
73 |
join(threadTerminationTimeout); |
74 |
} |
75 |
catch (InterruptedException e) { |
76 |
e.printStackTrace(); |
77 |
} |
78 |
} |
79 |
|
80 |
/** |
81 |
* Convenience method for accessing the current thread, |
82 |
* which casts to the expected class. If not, you get |
83 |
* null and it serves you right. |
84 |
* |
85 |
* @return task thread |
86 |
*/ |
87 |
public static final TaskThread currentTaskThread() { |
88 |
|
89 |
// TODO do we even need to check this? |
90 |
if (TaskThread.class.isInstance(Thread.currentThread())) { |
91 |
return TaskThread.class.cast(Thread.currentThread()); |
92 |
} |
93 |
|
94 |
return null; // don't like this much, but [shrug] |
95 |
} |
96 |
} |
0 |
+ text/plain |
97 |
+ text/plain |