Re: How to start a daemon without getting the warning?
You should call timer.cancel() on context stop. You can do this from a ServletContextListener. Ronald. Op woensdag, 27 oktober 2010 22:10 schreef Leon Rosenberg rosenberg.l...@gmail.com: Hello, I'm getting following warning with 6.0.29, after shutdown: SEVERE: The web application [/moskitodemo] appears to have started a thread named [MoskitoMemoryPoolReader] but has failed to stop it. This is very likely to create a memory leak. here's the snapshot of the code that starts the thread: public class BuiltInMemoryPoolProducer implements IStatsProducer{ /** * Timer instance for this producer type. */ private static final Timer timer = new Timer(MoskitoMemoryPoolReader, true); ... public BuiltInMemoryPoolProducer(MemoryPoolMXBean aPool){ timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { readMemory(); } }, 0, 1000L*60); ...} to my knowledge this thread is a daemon. This knowledge is also shared by jstack: MoskitoMemoryPoolReader daemon prio=5 tid=10883f800 nid=0x11a9b2000 in Object.wait() [11a9b1000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on 10a1120d0 (a java.util.TaskQueue) at java.util.TimerThread.mainLoop(Timer.java:509) - locked 10a1120d0 (a java.util.TaskQueue) at java.util.TimerThread.run(Timer.java:462) So, how can I avoid this warning and where's the bug. regards Leon - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
How to start a daemon without getting the warning?
Hello, I'm getting following warning with 6.0.29, after shutdown: SEVERE: The web application [/moskitodemo] appears to have started a thread named [MoskitoMemoryPoolReader] but has failed to stop it. This is very likely to create a memory leak. here's the snapshot of the code that starts the thread: public class BuiltInMemoryPoolProducer implements IStatsProducer{ /** * Timer instance for this producer type. */ private static final Timer timer = new Timer(MoskitoMemoryPoolReader, true); ... public BuiltInMemoryPoolProducer(MemoryPoolMXBean aPool){ timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { readMemory(); } }, 0, 1000L*60); ...} to my knowledge this thread is a daemon. This knowledge is also shared by jstack: MoskitoMemoryPoolReader daemon prio=5 tid=10883f800 nid=0x11a9b2000 in Object.wait() [11a9b1000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on 10a1120d0 (a java.util.TaskQueue) at java.util.TimerThread.mainLoop(Timer.java:509) - locked 10a1120d0 (a java.util.TaskQueue) at java.util.TimerThread.run(Timer.java:462) So, how can I avoid this warning and where's the bug. regards Leon - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: How to start a daemon without getting the warning?
From: Leon Rosenberg [mailto:rosenberg.l...@gmail.com] Subject: How to start a daemon without getting the warning? to my knowledge this thread is a daemon. Which isn't really relevant in the situation where only the context is being stopped, not the entire JVM. how can I avoid this warning and where's the bug. The bug is in failing to implement a ServletContextListener that can stop the thread. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to start a daemon without getting the warning?
On Wed, Oct 27, 2010 at 10:43 PM, Caldarale, Charles R chuck.caldar...@unisys.com wrote: From: Leon Rosenberg [mailto:rosenberg.l...@gmail.com] Subject: How to start a daemon without getting the warning? to my knowledge this thread is a daemon. Which isn't really relevant in the situation where only the context is being stopped, not the entire JVM. Meaning that I have to implement own thread registry for all started threads? Anyone already did something like this by chance? Leon - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: How to start a daemon without getting the warning?
From: Leon Rosenberg [mailto:rosenberg.l...@gmail.com] Subject: Re: How to start a daemon without getting the warning? Meaning that I have to implement own thread registry for all started threads? Nobody's going to do it for you, since they're part of your webapp. (Might be an interesting beyond-spec extension for Tomcat, though.) Anyone already did something like this by chance? You might want to take a look at java.util.concurrent.ThreadPoolExecutor, or perhaps org.apache.commons.pool. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to start a daemon without getting the warning?
On Wed, Oct 27, 2010 at 11:39 PM, Caldarale, Charles R chuck.caldar...@unisys.com wrote: From: Leon Rosenberg [mailto:rosenberg.l...@gmail.com] Subject: Re: How to start a daemon without getting the warning? Meaning that I have to implement own thread registry for all started threads? Nobody's going to do it for you, since they're part of your webapp. (Might be an interesting beyond-spec extension for Tomcat, though.) What I mean is a registry-style-thing where i can register all my threads, timers and executors, and which will take care of them with a -ready-to-use- contextlistener i just have to add to my web.xml. Anyone already did something like this by chance? You might want to take a look at java.util.concurrent.ThreadPoolExecutor, or perhaps org.apache.commons.pool. Well, that would just move the problem from stopping Timer to calling shutdown on Executor, wouldn't it? - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to start a daemon without getting the warning?
2010/10/28 Leon Rosenberg rosenberg.l...@gmail.com: Well, that would just move the problem from stopping Timer to calling shutdown on Executor, wouldn't it? The problem is with the Thread.getContextClassLoader() for your thread. It contains a reference to the webapp classloader, and thus does not allow to GC it. Note, that the webapp classloader cannot be used anymore once the application is stopped. Any attempt to load classes through it will fail. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to start a daemon without getting the warning?
Hello Konstantin, On Wed, Oct 27, 2010 at 11:53 PM, Konstantin Kolinko knst.koli...@gmail.com wrote: 2010/10/28 Leon Rosenberg rosenberg.l...@gmail.com: Well, that would just move the problem from stopping Timer to calling shutdown on Executor, wouldn't it? The problem is with the Thread.getContextClassLoader() for your thread. It contains a reference to the webapp classloader, and thus does not allow to GC it. But I can't detect any obvious Thread.getContextClassLoader() calls in the code below: public class BuiltInMemoryPoolProducer implements IStatsProducer{ /** * The id of the producers. Usually its the name of the pool. */ private String producerId; /** * Associated stats. */ private MemoryPoolStats stats; /** * Stats container */ private ListIStats statsList; /** * The monitored pool. */ private MemoryPoolMXBean pool; /** * Timer instance for this producer type. */ private static final Timer timer = new Timer(MoskitoMemoryPoolReader, true); /** * Creates a new producers object for a given pool. * @param aPool */ public BuiltInMemoryPoolProducer(MemoryPoolMXBean aPool){ pool = aPool; producerId = MemoryPool-+pool.getName()+-+(pool.getType()==MemoryType.HEAP? Heap : NonHeap); statsList = new CopyOnWriteArrayListIStats(); stats = new MemoryPoolStats(producerId); statsList.add(stats); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { readMemory(); } }, 0, 1000L*60); readMemory(); } @Override public String getCategory() { return memory; } @Override public String getProducerId() { return producerId; } @Override public ListIStats getStats() { return statsList; } @Override public String getSubsystem() { return SUBSYSTEM_BUILTIN; } private void readMemory() { MemoryUsage usage = pool.getUsage(); stats.setCommited(usage.getCommitted()); stats.setUsed(usage.getUsed()); stats.setInit(usage.getInit()); stats.setMax(usage.getMax()); } /** * This method is used internally for virtual producers / stats. * @return */ MemoryPoolStats getMemoryPoolStats(){ return stats; } } Note, that the webapp classloader cannot be used anymore once the application is stopped. Any attempt to load classes through it will fail. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: How to start a daemon without getting the warning?
From: Leon Rosenberg [mailto:rosenberg.l...@gmail.com] Subject: Re: How to start a daemon without getting the warning? But I can't detect any obvious Thread.getContextClassLoader() calls in the code below: The problem isn't associated with calling the above method, it's actually that the webapp's classloader has been associated with your thread. If you reset the contextClassLoader for your thread, that /might/ avoid the memory leak when the webapp is stopped. However, if the thread retains any references to other webapp-related classes, you still have the leak. Best to manage your threads properly - which is a good bit trickier in a container environment than in a stand-alone program. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to start a daemon without getting the warning?
2010/10/28 Leon Rosenberg rosenberg.l...@gmail.com: Hello Konstantin, On Wed, Oct 27, 2010 at 11:53 PM, Konstantin Kolinko knst.koli...@gmail.com wrote: 2010/10/28 Leon Rosenberg rosenberg.l...@gmail.com: Well, that would just move the problem from stopping Timer to calling shutdown on Executor, wouldn't it? The problem is with the Thread.getContextClassLoader() for your thread. It contains a reference to the webapp classloader, and thus does not allow to GC it. But I can't detect any obvious Thread.getContextClassLoader() calls in the code below: public class BuiltInMemoryPoolProducer implements IStatsProducer{ (skipped the code, have not read it) If you mean setContextClassLoader(..), that happens in java.lang.Thread constructor, or more specifically in some private helper method called there (Thread.init()). The Thread is created by the Timer. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org