• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.OutOfMemoryError on server

 
Zheng Huang
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Yesterday I posted a message with topic "Will it ever be GCed?". Dave Boden gave a perfect answer. Thanks, Dave. I have another question. This is the real reason I posted a message yesterday.
I got the "OutOfMemoryError" on the server while many clients called. Is there any way to programatically check how memory are left?
My server code will create a thread for each clients call. The run() for each thread will do some time-consuming job. The server ends up createing a lot of threads when many clients call. Eventurally JVM for server runs out of memory and the server dies. I understand that "OutOfMemoryError" is unchecked exception. I will not be able to catch it. But how can I prevent the server from dieing like that? I would like the server to tell client this memory problem rather than die itself.
Any help would be greatly appreciated.
TIA
Zheng
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that your threads are being joined when their service is done, or returned to a pool, if you do it that way.
How many clients are you creating? I can't imagine that Sun's test harness will create so many threads as to run their JVM out of memory. Their are switches to allow a larger heap size in the JVM, if needed, but they want to see if your program works, not to test the hardware or the JVM.
 
Zheng Huang
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if it is for the real application? Does anybody give any thought on this?
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!