ASF Bugzilla – Attachment 26068 Details for
Bug 49159
Improve ThreadLocal memory leak clean-up
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Alternative approach to renewing threads
KillThreadsAfterContextReload.patch (text/plain), 4.79 KB, created by
Pid
on 2010-09-23 10:49:43 UTC
(
hide
)
Description:
Alternative approach to renewing threads
Filename:
MIME Type:
Creator:
Pid
Created:
2010-09-23 10:49:43 UTC
Size:
4.79 KB
patch
obsolete
>Index: java/org/apache/tomcat/util/threads/TaskThread.java >=================================================================== >--- java/org/apache/tomcat/util/threads/TaskThread.java (revision 0) >+++ java/org/apache/tomcat/util/threads/TaskThread.java (revision 0) >@@ -0,0 +1,96 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version 2.0 >+ * (the "License"); you may not use this file except in compliance with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ */ >+package org.apache.tomcat.util.threads; >+ >+/** >+ * @author pidster >+ * >+ */ >+public class TaskThread extends Thread { >+ >+ private long created; >+ >+ /** >+ * @param group >+ * @param target >+ * @param name >+ */ >+ public TaskThread(ThreadGroup group, Runnable target, String name) { >+ super(group, target, name); >+ this.created = System.currentTimeMillis(); >+ } >+ >+ /** >+ * @param group >+ * @param target >+ * @param name >+ * @param stackSize >+ */ >+ public TaskThread(ThreadGroup group, Runnable target, String name, long stackSize) { >+ super(group, target, name, stackSize); >+ this.created = System.currentTimeMillis(); >+ } >+ >+ /** >+ * @return the created >+ */ >+ public final long getCreated() { >+ return created; >+ } >+ >+ /** >+ * @param comparison >+ * @return >+ */ >+ public boolean isOlderThan(long comparison) { >+ return created < comparison; >+ } >+ >+ /** >+ * @param threadTerminationTimeout >+ */ >+ public void selfDestruct(long threadTerminationTimeout) { >+ >+ // TODO maybe unset the classloader >+ // TODO maybe clear out the threadLocals >+ // TODO maybe perform additional cleanup >+ >+ try { >+ join(threadTerminationTimeout); >+ } >+ catch (InterruptedException e) { >+ e.printStackTrace(); >+ } >+ } >+ >+ /** >+ * Convenience method for accessing the current thread, >+ * which casts to the expected class. If not, you get >+ * null and it serves you right. >+ * >+ * @return task thread >+ */ >+ public static final TaskThread currentTaskThread() { >+ >+ // TODO do we even need to check this? >+ if (TaskThread.class.isInstance(Thread.currentThread())) { >+ return TaskThread.class.cast(Thread.currentThread()); >+ } >+ >+ return null; // don't like this much, but [shrug] >+ } >+} > >Property changes on: java/org/apache/tomcat/util/threads/TaskThread.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain > >Index: java/org/apache/tomcat/util/threads/TaskThreadFactory.java >=================================================================== >--- java/org/apache/tomcat/util/threads/TaskThreadFactory.java (revision 1000480) >+++ java/org/apache/tomcat/util/threads/TaskThreadFactory.java (working copy) >@@ -38,7 +38,7 @@ > } > > public Thread newThread(Runnable r) { >- Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement()); >+ TaskThread t = new TaskThread(group, r, namePrefix + threadNumber.getAndIncrement()); > t.setDaemon(daemon); > t.setPriority(threadPriority); > return t; >Index: java/org/apache/catalina/core/StandardContextValve.java >=================================================================== >--- java/org/apache/catalina/core/StandardContextValve.java (revision 1000483) >+++ java/org/apache/catalina/core/StandardContextValve.java (working copy) >@@ -36,6 +36,7 @@ > import org.apache.catalina.valves.ValveBase; > import org.apache.tomcat.util.buf.MessageBytes; > import org.apache.tomcat.util.res.StringManager; >+import org.apache.tomcat.util.threads.TaskThread; > > /** > * Valve that implements the default basic behavior for the >@@ -223,7 +224,12 @@ > } > } > } >- >+ >+ // Test if the TaskThread is older than the context >+ if (TaskThread.currentTaskThread().isOlderThan(context.getStartTime())) { >+ long threadTerminationTimeout = 0L; // TODO retrieve from context attribute? >+ TaskThread.currentTaskThread().selfDestruct(threadTerminationTimeout); >+ } > } > >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 49159
:
25411
| 26068 |
26074
|
26097
|
26108
|
26150
|
26156
|
26157