Improve company productivity with a Business Account.Sign Up


Java - strange issue when hangs

Posted on 2010-08-28
Medium Priority
Last Modified: 2012-06-21

I'm using a standard Java logger (please see enclosed code). But application suddenly hangs! :-(

In particular - there is a "main" application which starts a copy of itself with different command line parameters. All instances of my Java application writes data to own log file (something like mainXXX.log and executorXXX.log, where XXX is a current timestamp).

I see that all test cases produce mainXXX.log =~ 1.3kb, executorXXX.log =~ 320-390 bytes size log files. And then it hang.

I may think the main application could hang but a child application cannot hang for sure!
Because it is very simple and straight-forward, and also I have noticed that if I comment out some log write calls then application will step a bit more further and hang in the different place than before, which I think means that it hanging exactly because of logging.

For example - I see that a child java.exe process hang after 5 writes to a log file. And that could be any log writes. By commenting log writes at the beginning of application I can see it steps futher.
If I kill the main java.exe process the child process unfreeze and continue working and logging.

Do you have any ideas - why it could hang in such way?
Could it be a blocking I/O calls for a java process?
Any ideas - what to check? How to solve?

Could it be because main application writes some data to STDIN for a child java process and then waiting data from STDOUT?

If standard logger is "bad" can you then recommend some good logger solution for Java?

public class MiscUtils
	public static void toLogger(Level pLevel, String pMsg)
		if (! return ;, pMsg);
		if (consoleOutputEnabled) 

// usage example 1
MiscUtils.toLogger(Level.INFO, "* Open db connection...");

// usage example 2
MiscUtils.toLogger(Level.WARNING, String.format("! Trying to load db driver (%1$s)...", pDrvName));

Open in new window

Question by:Dmitry_Bond
  • 4
  • 3
  • 2
  • +2
LVL 10

Accepted Solution

gordon_vt02 earned 1000 total points
ID: 33553387
How are you starting the child applications?  If you are using Runtime.exec(), make sure you are reading both the stdout and stderr streams of the child processes.  Those are buffered and if the buffer gets full, the process will hang.  I think the same thing applies if you are using ProcessBuilder.
LVL 10

Expert Comment

ID: 33553394
If that doesn't solve your problem, I'd run the code in a debugging session to see where the main app is actually locking up.
LVL 92

Assisted Solution

objects earned 1000 total points
ID: 33555434
take a thread dump to see why it is hanging

> If standard logger is "bad" can you then recommend some good logger solution for Java?

try log4j or slf4j
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 33556390
Yes, I'm using Runtime.exec() to run another copy of java.exe.
From created process I'm reading/writing StdIn and StoOut only, but no StdErr.
I assume it should not be the issue. Example - who cares if child process writing something to StdErr, if StdErr is not read by some other processes no issues expected. Correct?

I'm new in Java tools, could you please provide some details - how to do "thread dump"?

PS. I'm using "Eclipse Java EE IDE for Web Developers. Version: Helios Release. Build id: 20100617-1415".
LVL 92

Expert Comment

ID: 33556420
> who cares if child process writing something to StdErr, if StdErr is not read by some other processes no issues expected. Correct?


Author Comment

ID: 33556512
I think your example is not describing what we are discussing. Because in the example you provided it use only STDIN, STDOUT and there is nothing about STDERR. So, or example is wrong or idea shown incorrectly. Choose one option please.

Next thing - absolutely for sure the child process I'm creating in application is not writing anything to STDERR because it is quite simple and all executing I can see in a log - there are no any hints telling about errors or such stuff. So, I think that is not a "stream overflow and hang"  issue.
Also because - it write/read only few data to STDIN/STDOUT - about 300-500 chars before it hang, I doubt buffer size is so small... how could I know the default buffer size?

I just replaced logging with log4j (1.2.16) - everything starts to working fine - no more hangs, no more problems.
Could it be because of bugs in standard Logger object?
If yes, then rhetoric question - why Sun/Oracle/IBM included such "bad" Logger object into a standard?!

PS. I'm running it using JRE 1.5 - "IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Windows Vista x86-32 j9vmwi3223-20070426 (JIT enabled)". Seems exactly the Java 1.5 have be the target for project.

Just for a case I just also tested the same with Java 1.6.0_21 - it also hangs. :-\
LVL 92

Expert Comment

ID: 33557085
> Because in the example you provided it use only STDIN, STDOUT and there is nothing about STDERR. So, or example is wrong or idea shown incorrectly.

STDERR is the same as STDOUT
point is you need to consume all output from the process

Author Comment

ID: 33557124
> STDERR is the same as STDOUT. point is you need to consume all output from the process

Ok. Then it cannot be the reason of mentioned issue. Because the main process reads STDOUT.

Expert Comment

ID: 33581637
Dear Dmitry_Bond,

Both of mentioned propositions may cause it:
1. Blocking IO on logging - make sure you are using separate log files on fist and second jvm, on windows you can not even remove file opened for reading :D, even so called Administrator rights are not sufficient.
2. STDOUT and STDERR are separate pipes, not reading any of them may cause hang, do not use e.printStackTrace(), you can simply replace it with e.printStackTrace(System.out), remember to surround the whole invocation with try/catch(Exception e){e.printStackTrace(System.out);}, Most probably some RuntimeException (like NullPointerException) is causing writing to STDERR.


Author Comment

ID: 33609384
Absolutely for sure (without even a slight doubt!):
1)  - there are separate log files for different jvm. Actually only 2 jvm - every writing own log file.
2) - STDERR is not written at all! And that is true - no any errors appears while application working.

Also, as I already specified - I had only replaced standard Java logger with log4j and all things starts to working fine. Which means (as I see it) = STANDARD LOGGER HAS BUGS making application hang.

Any comments? Any ideas how to check what application is doing at the moment?
Stacktrace, etc? Can you recommend any tools to debug/trace/check java applications?
LVL 27

Expert Comment

ID: 37126730
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

584 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question