View | Details | Raw Unified | Return to bug 49159
Collapse All | Expand All

(-)java/org/apache/tomcat/util/threads/TaskThread.java (+96 lines)
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
(-)java/org/apache/tomcat/util/threads/TaskThreadFactory.java (-1 / +1 lines)
Lines 38-44 Link Here
38
    }
38
    }
39
39
40
    public Thread newThread(Runnable r) {
40
    public Thread newThread(Runnable r) {
41
        Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement());
41
        TaskThread t = new TaskThread(group, r, namePrefix + threadNumber.getAndIncrement());
42
        t.setDaemon(daemon);
42
        t.setDaemon(daemon);
43
        t.setPriority(threadPriority);
43
        t.setPriority(threadPriority);
44
        return t;
44
        return t;
(-)java/org/apache/catalina/core/StandardContextValve.java (-1 / +7 lines)
Lines 36-41 Link Here
36
import org.apache.catalina.valves.ValveBase;
36
import org.apache.catalina.valves.ValveBase;
37
import org.apache.tomcat.util.buf.MessageBytes;
37
import org.apache.tomcat.util.buf.MessageBytes;
38
import org.apache.tomcat.util.res.StringManager;
38
import org.apache.tomcat.util.res.StringManager;
39
import org.apache.tomcat.util.threads.TaskThread;
39
40
40
/**
41
/**
41
 * Valve that implements the default basic behavior for the
42
 * Valve that implements the default basic behavior for the
Lines 223-229 Link Here
223
                }
224
                }
224
            }
225
            }
225
        }
226
        }
226
                
227
228
        // Test if the TaskThread is older than the context
229
        if (TaskThread.currentTaskThread().isOlderThan(context.getStartTime())) {
230
            long threadTerminationTimeout = 0L; // TODO retrieve from context attribute?
231
            TaskThread.currentTaskThread().selfDestruct(threadTerminationTimeout);
232
        }       
227
    }
233
    }
228
234
229
235

Return to bug 49159