简体   繁体   中英

Memory Leak in Tomcat 6.0 application

I am working with socket application. I have a JAVA TCP listener as a part of web application. I have defined my TCP Listener as a servlet context listener inside web.xml, so once I start my tomcat my TCP listener become active and wait for incoming request coming from GPS device.

Once my tomcat6.0 starts then TCP listener is able to read all incoming request but, just after 5 minute, I get an error like this "The web application appears to have started a thread named but has failed to stop it. This is very likely to create a memory leak.".

Please help me how to fix this issue. As I am creating simultaneously many threads to handle the incoming request since we have 10K GPS device which communicates with my TCP listener. We have business reason to create a single thread for single device and process incoming request.

Please help me to figure out actual issue.

Thanks in advance.

The web application appears to have started a thread named but has failed to stop it.

Please help me how to fix this issue.

Well, maybe stop that thread? Looks like your error message is incomplete, it typically has a thread name (or maybe your threads have empty ( "" ) name?

This error in Tomcat is not critical, but you should investigate why it appears, have a look at: Is this very likely to create a memory leak in Tomcat? and especially at Tomcat 6 memory leaks log entries which targets threads.

In order to stop a thread check out: How to stop a thread that is running forever without any use .

I'll assume that you've checked the JVM settings with which you start Tomcat. Maybe your memory is too low.

I'd recommend that you download Visual VM 1.3.3, install all the plugins, start your Tomcat application, and attached Visual VM to the JVM. It'll show you what's happening in memory, CPU, objects created, threads, etc.

You showed no code, and you have no data. You'll never solve this problem this way. No one here can help you much, either. Your code is creating too many objects. You need to find out why and stop it.

We have business reason to create a single thread for single device and process incoming request.

You might have a business reason, but your technical reasons might not be sound. Each HTTP request that comes in has a single thread. Isn't that what you want? When a GPS posts a request you have a single thread to handle it, right? Why must you create many threads with each request? What are those threads doing?

Another approach might be to refrain from creating threads. When a request comes in from a device, find some unique tag like a device id and add that message to the session history for that device. I haven't heard any justification for creating threads so far.

I don't know if you're taken the trouble to write your own server, but I'd recommend that you look into using Netty. It's an all-Java server based on non-blocking IO that's born to handle high traffic. They know how to handle threads. Maybe you can just use it and add your processing logic to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM