I am having a hard time tracking this down since the profiler keeps crashing (hotspot error). Before I go too deep into figuring it out I’d like to know if I really have a problem or not 🙂
I have a few thread pools created via: Executors.newFixedThreadPool(10); The threads connect to different web sites and, on occasion, I get connection refused and wind up throwing an exception.
When I later on call Future.get() to get the result it will then catch the ExecutionException that wraps the exception that was thrown when the connection could not be made.
The program uses a fairly constant amount of memory up until the point in time that the exceptions get thrown (they tend to happen in batches when a particular site is overloaded). After that point the memory again remains constant but at a higher level.
So my question is along the lines of is the memory behaviour (reported by “top” on Unix) expected because the exceptions just triggered something or do I probably have an actual leak that I’ll need to track down? Additionally when Future.get() throws an exception is there anything else I need to do besides catch the exception (such as call Future.cancel() on it)?
EDIT: so I did tale a look with a couple of tools and from the Java point of view there is nothing going on memory leak wise. I’ll play around with some other code that lives for a long time and throws an exception after a while and see if the memory reported by “top” also increases. Seems like it may just be some sort of oddity.
Does your Java process ever actually exit with the exception java.lang.OutOfMemoryError ? If not, its unlikely that you have a leak. Of course, you can always attach to the Java process with JConsole, capture a heap dump, and open it in a free tool like HPjmeter to find out really quickly.