Lines 16-37
Link Here
|
16 |
*/ |
16 |
*/ |
17 |
package org.apache.tomcat.util.threads; |
17 |
package org.apache.tomcat.util.threads; |
18 |
|
18 |
|
|
|
19 |
import org.apache.juli.logging.Log; |
20 |
import org.apache.juli.logging.LogFactory; |
21 |
|
19 |
/** |
22 |
/** |
20 |
* A Thread implementation that records the time at which it was created. |
23 |
* A Thread implementation that records the time at which it was created. |
21 |
* |
24 |
* |
22 |
*/ |
25 |
*/ |
23 |
public class TaskThread extends Thread { |
26 |
public class TaskThread extends Thread { |
24 |
|
27 |
|
|
|
28 |
private static final Log log = LogFactory.getLog(TaskThread.class); |
25 |
private final long creationTime; |
29 |
private final long creationTime; |
26 |
|
30 |
|
27 |
public TaskThread(ThreadGroup group, Runnable target, String name) { |
31 |
public TaskThread(ThreadGroup group, Runnable target, String name) { |
28 |
super(group, target, name); |
32 |
super(group, new WrappingRunnable(target), name); |
29 |
this.creationTime = System.currentTimeMillis(); |
33 |
this.creationTime = System.currentTimeMillis(); |
30 |
} |
34 |
} |
31 |
|
35 |
|
32 |
public TaskThread(ThreadGroup group, Runnable target, String name, |
36 |
public TaskThread(ThreadGroup group, Runnable target, String name, |
33 |
long stackSize) { |
37 |
long stackSize) { |
34 |
super(group, target, name, stackSize); |
38 |
super(group, new WrappingRunnable(target), name, stackSize); |
35 |
this.creationTime = System.currentTimeMillis(); |
39 |
this.creationTime = System.currentTimeMillis(); |
36 |
} |
40 |
} |
37 |
|
41 |
|
Lines 42-45
Link Here
|
42 |
return creationTime; |
46 |
return creationTime; |
43 |
} |
47 |
} |
44 |
|
48 |
|
|
|
49 |
/** |
50 |
* Wraps a {@link Runnable} to swallow any {@link StopPooledThreadException} |
51 |
* instead of letting it go and potentially trigger a break in a debugger. |
52 |
*/ |
53 |
private static class WrappingRunnable implements Runnable { |
54 |
private Runnable wrappedRunnable; |
55 |
WrappingRunnable(Runnable wrappedRunnable) { |
56 |
this.wrappedRunnable = wrappedRunnable; |
57 |
} |
58 |
@Override |
59 |
public void run() { |
60 |
try { |
61 |
wrappedRunnable.run(); |
62 |
} catch(StopPooledThreadException exc) { |
63 |
//expected : we just swallow the exception to avoid disturbing |
64 |
//debuggers like eclipse's |
65 |
log.debug("Thread exiting on purpose", exc); |
66 |
} |
67 |
} |
68 |
|
69 |
} |
70 |
|
45 |
} |
71 |
} |