• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.exit(0) hangs  RSS feed

 
sam wan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java application, which generates a html file. Here is how
main method looks like

public static void main(String args[])
{
//Create a new file using File class.
//Make backend calls and get data.
//Write to the file using filewriter and close the file.
System.out.println("abc.html is generated succesfully");
System.exit(0);
}

This code works fine on windows environment, but when put it on Unix
solaris environment, it just hangs. On Solaris, it prints the above
System.out.println statement fine and even generates abc.html, but it just
hangs at System.exit(0).

Here is the process I see running and needs to do kill -9 to get out of this
/opt/was4/dev/AppServer/java/jre/bin/../bin/sparc/native_threads/java -DDISPLAY

Any clues how to fix this?
Your help will be highly appriciated.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try it without System.exit (0) ?
Do you need a return value?
 
Hari Gangadharan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is your application, or one of the APIs you are using is creating a thread which is not finishing on System.exit(0) call. Hence your application is waiting for the other thread to die.

Sometimes developers code the stopping of threads in the finalize methods and the finalize method may not be invoked on termination in some Java VM implementations (it is not necessary to invoke finalize before a VM is terminated). Maybe the Windows implementation invokes the finalize method of all the objects before termination and the Solaris Java VM is not doing that. Hence a thread might have not killed itself and kept the application hung.

My advise is to look for the threads that are started in this application and make sure that you make explicit calls to stop them before you call the System.exit(0).
[ June 28, 2004: Message edited by: Hari Gangadharan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!