1

There are many threads in my Java server. It hangs when one thread recursive invoke a method infinitely. After the method is invoked 54 times, the process hang, and there is no any log like "StackOverFlow" or "OutOfMemory".

However, as I know, only the thread with the problem will crash, other threads can work normally.

environment:

Linux version 2.6.31-20-server (buildd@crested) (gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8) ) java version "1.6.0_18" Java(TM) SE Runtime Environment (build 1.6.0_18-b07) Java HotSpot(TM) 64-Bit Server VM (build 16.0-b13, mixed mode)

2
  • Erm... you pretty much already answered your question? You're in an infinite loop of invoking a recursive method.. What exactly is your question? Commented Nov 30, 2010 at 11:39
  • "It hangs when one thread recursive invoke a method infinitely." Yes, that's why it hangs. So why are you asking why it hangs? We aren't psychic; we can't see the code for that thread, so we can't help you fix the infinite recursion unless you show the code. Commented Nov 30, 2010 at 11:40

4 Answers 4

2

All threads require stack space. Every time you invoke a method recursively the stack expands - eventually you're gonna run out.

The number of iterations you manage depends on the exact code being run.

Sign up to request clarification or add additional context in comments.

Comments

1

Generate a thread dump which will show you a stack trace for each Java thread in the VM. This will tell you what the threads are doing when the JVM hangs.

To generate a thread dump, on UNIX platforms, you can use the command kill -QUIT process_id, where process_id is the process id of your Java program.

On Windows, you can enter the key sequence <ctrl><break> in the window where the Java program was started. Sending this signal instructs a signal handler in the JVM, to recursively print out all the information on the threads and monitors inside the JVM.

Comments

1

Ask for a thread dump to see what your threads do. Set name for each thread you fork to identify them correctly. I suppose there could be also a dead lock on object monitors as well. I suggest use JProfiler to find the object the threads are blocked on.

On the other hand infinite recursion is not soo good. Avoid this, or define limit for it.

Comments

0

You've answered your question:

It hangs when one thread recursive invoke a method infinitely.

My suggestion is to not invoke a method infinitely, you're expanding your stack very quickly as you're recursively calling a method.

What are you trying to do with threads? Can you optimise your code to invoke the method without an infinite loop?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.