my dog learned polymorphism
The moose likes Threads and Synchronization and the fly likes Getting a memory leak on ScheduledExecutorService Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Getting a memory leak on ScheduledExecutorService " Watch "Getting a memory leak on ScheduledExecutorService " New topic
Author

Getting a memory leak on ScheduledExecutorService

Tom Davis Sr
Greenhorn

Joined: May 24, 2009
Posts: 15
I am trying the basic example from the java ScheduledExecutorService API. After a few minutes, I see the memory usage go up. My task has to run for a very long time, hence I am concerned that it could crash the application. Any input would be appreciated.

Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

It will be better to profile the JVM and find out what is taking memory, otherwise the memory leak is merely a speculation.
You can use jmap at the minimum to get a dump of the heap and later view it using jhat


apigee, a better way to API!
Tom Davis Sr
Greenhorn

Joined: May 24, 2009
Posts: 15
Thank you Nitesh. I had this sample program (which really has one print statement to execute every 2 secs) running for 2 hours and I noticed that the memory usage on Windows Task Manager is still going up. I expected it to remain constant after a while.

Is it possible that the JVM would still need more memory after all this time?
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 370

JVisualvm in the bin folder of your jdk is also quite useful, you'll get a "saw tooth" graph as memory rises and if that grapgh has an underlying trend upwards you have an issue.

Just leave it running a long time then look at which objects are using the most memory (string's are always near the top but check what those strings are content wise ... I once found 100Mb's of log file in memory from a Sun bug ..lol) then look for any objects you weren't expecting ;-)


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Getting a memory leak on ScheduledExecutorService
 
Similar Threads
ScheduleExecutorService and stopping threads
Synchronizing without blocking in a servlet filter
Countdown timer in java
How to stop execution of ScheduledExecutorService
need store object for 5 mins