JVM 1.5 hang at system.exit(): how to debug ?

Our Java application seems to sometimes hang indefinitely at System.exit().
So far, we have observed that:
- the hang does not happen when running JDK 1.4, but only with JDK 1.5 (we are trying to migrate to JDK 1.5.0_06)
- it seems that if we comment out code that calls PrinterJob.print(), the hang does not happen
- the hang can be observed on all our machines (different models), except one that is misteriously not impacted. OS is WinXP SP2.
- when our software has sent a printer job to the printer and is running JDK 1.5, the problem can be reproduced after at most 4 or 5 tries, usually 1 or 2 runs being sufficient.
- we have not been able to narrow the problem to a simple testcase (only reproduced using automated testcases on our application, which is 200.000+ LOC....)
- when the JVM is stuck in System.exit, the process can be killed using the task explorer with the usual "program does not respond" and subsequent "send problem report" wizard after having killed it. (not to sure on exact wording in english...).
We suspect a hard-to-hit regression or behavior change in JDK1.5 (there's no reason a java application could hang at System.exit(), right ?), but the above information is certainly far from being sufficient to open a bug report.
So, any help to help us further identify the problem would be appreciated.
More precisely, is there any way to try to understand the problem using a crash dump, or something like this ?
Thanks

I doubt that it hangs at System.exit(). Use jConsole (comes with your JDK) to connect to your application and inspect all running Threads which block at what exception stack trace.

Similar Messages

  • Function Exit , How to Debug

    hi
    i have created five function with four are hidden and one function Exit , for Function Exit i am using functin module , but when i put a Breakpoint in Function module and run the BPS , Debugging is not working out , it directly executing.
    can anyone help me how to debug the function exit(Function Module) before running the report

    Hi,
    Go to that corresponding parameter group for that exit function, right click -execute with trace..it will take you to debugging screen..  (put a breakpoint before execution)

  • System.exit(0) - Avoid JVM termination

    Hi,
    Is there any possibility to avoid JVM termination when we use system.exit(0).
    I have created my own SecurityManager.
    public class MySecurityManager extends SecurityManager {.....}, and I can able to get S.O.P at public void checkPermission(final Permission permission) {..} and public void checkExit(int status) {..} in SecurityManager , My code in main() is
    MySecurityManager mySM = new MySecurityManager();
              System.setSecurityManager(mySM);
    System.out.println("Before......");
    System.exit(0);
    System.out.println("After......");
    i cant able to get SOP "After.....",
    Is there any possibility to raise exceptions when i introduce exit(0) in my java file.....? or Is there any possibility to avoid JAVA termination when i use System.exit(0).
    Thankx in Advance

    uh, System.exit is defined as the command to
    terminate the JVM. You can avoid that by not calling
    System.exit...Or do just what the OP tried to do.
    class Test {
         public static void main(String args[]) throws Exception {
              System.setSecurityManager(new ExitHandlingSecurityManager());
              System.out.println("Before");
              try {
                   System.exit(1);
              } catch (SecurityException e) {
                   System.err.println("Couldn't exit the VM: " + e.getMessage());
              System.out.println("After");
    class ExitHandlingSecurityManager extends SecurityManager {
         @Override
         public void checkExit(int arg0) {
              throw new SecurityException("You aren't allowed to terminate VM");
    }Prints:
    Before
    Couldn't exit the VM You aren't allowed to terminate VM
    After
    Kaj

  • Prevent System.exit(0)

    Hi Everybody!
    I have the following problem.
    I am developing an web-application running on a Tomcat server.
    Furthermore I am using some additional libraries, from which I only have the class-files. Nevertheless I decompiled them and found, that one method calls a System.exit(0) in its catch block, and this is horrible, because the server always shuts down in case of failure.
    What shall i do to prevent this? Altering the library will not be possible. Any ideas?
    I created a small example to point out my problem:
    public class Testing {
         private void methodA(String s) {
              try {
                   int i = Integer.parseInt(s);
                   System.out.println("Value of i: " +i);
                   Thread.sleep(1000);
              catch (Exception e) {
                   e.printStackTrace();
                   System.exit(0);
         }     //methodA
         public static void main(String[] args) {
              Testing t = new Testing();
              for (int i = 0; i < 10; i++) {
                   if (i == 5)
                        t.methodA("a");
                   else
                        t.methodA(String.valueOf(i));
              }     //for
    }Just think of methodA() as an method that can not be altered... How can I force the for-loop to continue when methodA() fails?
    (This is not my actual problem, but it points out my problem... ;)
    Thanks in Advance!
    Stef

    I was able to solve the problem by using the following code :-
    final SecurityManager securityManager = new SecurityManager()
         public void checkPermission(Permission permission)
              //This Prevents the shutting down of JVM.(in case of System.exit())
         if ("exitVM".equals(permission.getName()))
         throw new SecurityException("System.exit attempted and blocked.");
    System.setSecurityManager(securityManager);
    Hope it helps some one ..................... ;)

  • HI how to debug the whole SC creation process

    Hi
    I need small help from all you great guys.
    I am working with EBP application.
    I want to know the process of creation of shopping cart to the creation of PO in the r/3 system.
    How to debug the whole process. I can create a shopping cart in the EB web. I want to know what is hapening in the backend during the creation of shopping cart.
    I know the web transaction for the creation of the shopping cart. I tried to debug the process by going SE80 and giving the web transaction , but it is very cumbersome process and i was confused. Is there any way i can know what is happening in the backend and how the SC data is transferred to the bacend and how PO is created in the R/3 system
    sankar

    Hi Sankar Rao
    we can debug the shopping cart from sap GUI via tran.  /nBBPSC01
    1 Click on internal Goods/services  and select the product for which you want to create a SC and press enter.
    2 In command window input  /h and press enter
    3 Click on the button Order it will go in debug mode.
    4 Insert break points on Statement - Select
    5 Insert break points on Statement - Insert
    6 Insert break points on Statement -  update
    and press F5 key to move one step ahead and F8 key to halt directly at each break point.This way go upto the save mode and order your SC at run time in debug mode.
    regards,
    Nimish Sheth
    NB Do rewards points for helpful anwsers.

  • How  to track System.exit(0) call

    hi there,
    how can i trace the System.exit(0) function call in my program.
    i.e as we know which class is being loaded into the jvm by overriding
    the classloader, can we similarly know when is our jvm going to be
    destroyed. here iam invoking jvm from my windows program using invocation api.
    any help is mostly appreciated.
    thanks in advance
    bye
    ramana

    Not sure I know what you are asking.
    You could create a security manager which prevents exit() from being called.
    You could replace System using the bootstrap command line option. Although if you do that you can not distribute it due to the license agreement. Once replaced you can do anything you want in the application.
    You could use Runtime.addShutdownHook() if you just want to do something when the application exits.

  • How stop call to System.exit but allow them to install Securitymanager?

    I have an application that allows you to start a java application from inside it (it then gives you monitoring capabilities). I want this to work with pretty much any desktop application, even those that require their own security manager. However, i don't want their application to be able to shutdown the jvm. How can I do this?
    As far as I can tell, there's no way to allow them to add the securitymanager, "wrapped" by mine is there?
    And I thought of using AccessController.doPriviledgedAction(...) and giving them a context where they can add a security manager but not call system.exit, but then if they do add a security manager, won't it have the final say on system.exit calls?
    Is there a solution here?

    6tr6tr wrote:
    Thanks for the reply!
    Hmmm, the problem with that is I need the users to be able to use my application without access to that app's source code. So they need to be able to run that program (as 3rd party black-boxed code) inside my app and still have this work properly. Is there another way?
    Source code?
    You don't need any source code for what I suggested.
    If a frame/jframe tries to exit on close, I can grab and stop that. my problem is if some random code tries to call system.exit(). Is there any other way to intercept it?
    UPDATE: the only solution i could come up with is to use bytecode engineering + classloading.
    Which I doubt will help if they call it with reflection.
    You could use the bootstrap command line options and replace System with your own version. Add some functionality to how it sets up the security manager and/or make System.exit() do nothing, but provide another name for yourself.

  • How to "kill" AWT Event Queue thread without using System.exit()?

    When I run my program and the first GUI window is displayed a new thread is created - "AWT-Event Queue". When my program finishes, this thread stays alive and I think it causes some problems I have experienced lately.
    Is there any possibility to "kill" this thread without using System.exit() (I can't use it for some specific reasons)

    All threads are kept alive by the JVM session. When you use System.exit(int) you kill the current session, thus killing all threads. I'm not sure, though...
    What you could do, to make sure all threads die, is to make ever thread you start member of a thread group. When you want to exit you app, you kill all the threads in the thread group before exit.
    A small example:
    //Should be declared somewhere
    static ThreadGroup threadGroup = new ThreadGroup("My ThreadGroup");
    class MyClass extends Thread {
    super(threadGroup, "MyThread");
    Thread thread = new Thread(threadGroup, "MySecondThread");
    void exit() {
    //Deprecated, seek alternative
    threadGroup.stop();
    System.exit(0);
    }

  • Catching System.exit() or How to avoid System.exit() - Third Party Tool ???

    Hi All,
    I am using a third party tool which is internally calling System.exit sometimes and my application
    got terminated most of the times.
    It is happening always when i call a particular method of that third party tool.
    Is there any way to catch or avoid the System.exit while using the particular method?
    I need this urgently...Please kindly help.....
    Thanks,
    J.Kathir

    There's a fair bit to it, and you should refer to the appropriate java Tutorials. Bascially you create a .policy file and install a sercurity manager with:
    System.setSecurityManger(new SecurityManager());The policy file grants a set of permissions to various "code sources", basically each codesource is a classpath entry. You could grant "AllPermissions" to your own code, and a more restricted set of permissions to the application you're running. But you can't subtract permissions, i.e. you can't say "this code can do anything except call System.exit().
    I doubt this is going to provide you with a good solution. It's tiresome to set up, and when the client app called System.exit it would crash, which might not result in a clean status.
    I'd consider if you should be using this client app in the same JVM, rather than creating a subordinate JVM using Runtime.exec.

  • How many JVM can exist in one system

    How many JVM can exist in one system?

    r u talking abt installed JDK's or JVM loaded in to physical memory?
    if installed JDK's then Caffeine0001 is right.
    and if u r talking abt JVM loaded in to physical memory then again answer is same as above i.e. whatever your machin's physical memory can effort.

  • How can we know that JVM is running in our system?

    how can we know that JVM is running in our system?

    On a *dows system you can use pslist and the like:
    http://www.sysinternals.com/Utilities/PsTools.html
    http://www.sysinternals.com/Utilities/PsList.html

  • How to intercept "System.exit"?

    I am writing a large GUI application that optionally spawns other GUI threads. These spawned threads are special-purpose text editors. It is important that the editor knows when it is about to be closed, so that it can prompt the user to save a modified file.
    The editors are based upon javax.swing.JFrame, and I have overridden the "windowClosing" method of a WindowAdapter to check file status and prompt when necessary. This method performs as desired when I close the editor window manually. However, when I close the main application (which calls System.exit(0) ), the editor frames also close without any invocation of my windowClosing method.
    Is there any way the dependent editor JFrame can be alerted that the virtual machine is about to be ended? I could probably keep a list in my main application of all the dependent processes that need to be cleanly ended, but it would be much simpler (and so much more object-oriented) if the dependent thread could take care of itself!

    MarkHausman wrote:
    As you suggested, I posted this question on the Swing forum.
    For those who are interested: the Swing solution I was offered was to make use of the static function Frame.getFrames(). This allows access to all frames launched by an application. By putting this call in my main shutdown method, I can identify all spawned editor frames and call each one's shutdown method.
    This is not as satisfying as my original desire, to have the spawned frame recognize when the VM is about to close, but it is easy enough to implement that I am going with it.And why wouldn't addShutdownHook() work?

  • How do I exit a java program based on condition can i use system.exit

    I have java program that is called by another program that I dont have control on. My program returns a bigdecimal... but if the ordernumber is empty in my program i dont wnat to do anything.. does system.exit work in that condition... i put it int he else if ordernumber is empty condition.. but i dont think that is the right approach..

    When software module is expected to bring some result, it should bring the result, positive or negative. I think you should check what your counterpart software expects as positive or negative result. And then implement your software this way. You can use System.exit, but this call is employed usually to indicate status with the software after it's completion and not to return any resulting value.
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#exit(int)

  • System.exit(0)   error in program.

    Any help appreciated. Let me first put my code here:
    Converts money using CurrencyConverter, there's another class I haven't posted here!! (which calculates conversion)
    import java.util.* ;
    public class CurrencyConverterTester
      public static void main(String[] args)
        Scanner in = new Scanner(System.in) ;
        System.out.println("How many euros is one dollar?") ;
        String input = in.nextLine() ;
        double rate = Double.parseDouble(input) ;
        CurrencyConverter myconverter = new CurrencyConverter(rate);
        System.out.println("Dollar value (Q to quit)") ;
        input = in.nextLine() ;
        while (true) {
          if (input == "Q"){
            System.exit(0);
            break;}
          else {
          System.out.println(input + " dollar = " +  myconverter.convert(Double.parseDouble(input)) + " euros");
          input = in.nextLine();
          continue;}   
    }The issue is that the program won't terminate when I enter Q as my input?? I'm guessing it might have something to do my conversion from string to double in the 'else' statement, but not sure. Also, if you can suggest a more simpler method for the last 'while' statement, that would be helpful as well. Thanks. (noob to java)

    paulcw wrote:
    Curse Gosling for making &#43; syntactic sugar for string append, but not overloading any other operators.@Paul
    What did you expect from a duck ;-)
    Seriously, yep, maybe it would have been better for noobs if the syntax of Java Strings was consistent with other kinds of Object... or maybe it would have been better if == was compiler-magiced into stringA.equals(stringB)... and the left and right shift operators have promise, and of course that way lies MADNESS, as witnessed in C&#43;&#43; ;-)
    @OP... You are (IMHO) using the break, continue and especially System.exit() inappropriately... see my comments in your code...
        System.out.println("Dollar value (Q to quit)") ;
        input = in.nextLine() ;
        // while-true-loops are a "fairly usual" way of doing this kind of stuff,
        // but that doesn't make them "the preferred option". Typically you would
        // explore more "vanilla approaches" (which don't rely on the break and
        // continue statements)... leaping straight to the "tricky approach" means
        // you haven't (most often out of sheer laziness) thought it through... and
        // ALL good computer programs are thoroughly thought through (yep, try
        // saying that three times fast, especially after three beers).
        while (true) {
          // You don't compare Strings using ==
          if ( "Q".equalsIgnoreCase(input) ) {
            // Either of the following statements will do the job. The call to exit
            // will exit the JVM, therfore the break statement cannot be reached,
            // so it is superflous, so it's presence is just a bit confusing. Having
            // said that, "real programmers" don't use System.exe routinely, only in
            // the case of an emergency, such as handling a fatal-error, such as an
            // out-of-memory condition... an even then it's usually indicative of a
            // poor "system design", because it terminates the JVM which is running
            // this program without giving anything else in the program a chance to
            // clean-up after itself... like ask the user if they want to save there
            // work, or whatever.
            // I would use break (if anything) instead of System.exit
            // ... and if I wrote the Java tutorials, exit wouldn't be mentioned at
            // all until both "normal" flow control, and exception handling had both
            // been thoroughly covered.
            System.exit(0);
            break;
          } else {
            // I would break this line up, probably into three lines, simply becuase
            // it's syntatically "a long line".
            // Also the name "myconverter" doesn't tell what the class is/does.
            // IMHO, currencyConverter would be a better (more meaningful) name.
            // HERE'S HOW I WOULD WRITE IT
            // double dollars = Double.parseDouble(input);
            // double euros = currencyConverter.convert(dollars);
            // System.out.println(input + " dollar = " + euros + " euros");
            System.out.println(input + " dollar = " +  myconverter.convert(Double.parseDouble(input)) + " euros");
            input = in.nextLine();
            // This continue statement is superflous. continue says "go back to the
            // top of loop, reevaluate the loop-condition (true in this case) and
            // (if the condition is still true) "Play it again Sam".
            // ... which is exactly what will happen without this continue statement
            // and hence (IMHO) your code is easier to follow without it, simply
            // because another programmer may waste there time trying to figure out
            // WHY that continue statement is present.
            continue;
        }*ALSO:* The format of that code totally sucks. Braces all over the place; improper indentation. No wonder you're struggling to read your own code. Please read and abide the [The Java Code Conventions|http://java.sun.com/docs/codeconv/] (at least until you have the requisite experience to formulate credible and compelling arguments as to why your "style" is superior to the standard, and that's no small ask). Yes this is *important*... trust me on this (for now)... especially if you are going to ask for help on the forums... You're effectively wasting our time asking us to decipher your code because you are too lasy to format it correctly... and I for one find that "self entitled" attitude ugly, and offensive... Help us help you... you know?
    And BTW.... Here's how I would actually do it.... no funky while-true, break, or continue... just a plain-ole'-while-woop....
    package forums;
    import java.util.Scanner;
    public class KRC
      private static final Scanner SCANNER = new Scanner(System.in);
      public static void main(String[] args) {
        try {
          String input = null;
          while ( !"Q".equalsIgnoreCase(input=enterDollarAmount()) ) {
            System.out.println(input + " dollars is " +  Double.parseDouble(input) + " euros.");
            System.out.println();
        } catch (Exception e) {
          e.printStackTrace();
      private static String enterDollarAmount() {
        System.out.print("Please enter an amount in dollars : ");
        return SCANNER.nextLine();
    }Edited by: corlettk on 25/10/2009 10:21 ~~ Distant Monarching Forum Markup!

  • System.exit(o) in Swing

    Hi,
    In my Swing application, as soon as I start the main() method, a dialog containing Username and Password fields with OK and Cancel buttons gets popped-up. I have a propertyChangeListener which gets notified when Ok or cancel is pressed and when Cancel is pressed, System.exit(0) is called to exit the JVM.
    So, there are two threads running -
    One - the main thread which invokes the dialog pop-up
    Second - the propertychangelistener which calls the System.exit(0) on pressing Cancel button.
    So, at times, after pressing cancel button, the application does not exit but invokes the previously running thread (main thread). But this does not happen always.
    Could you please let me know why the application does not terminate completely and how to resolve this?
    Thanks in advance!

    Hi,
    As I had already mentioned in my previous post -
    Here is the pseudo-code which fails to terminate on pressing Cancel button at times.
    ================The Login dialog code=============
    public LoginDialog()
    // Other code
    JOptionPane optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]);
    optionPane.addPropertyChangeListener(new PropertyChangeListener()
    public void propertyChange(PropertyChangeEvent e)
              Object value = optionPane.getValue();
              if (value.equals(YES))
              else
    // user closed dialog or clicked cancel
    setVisible(false);
    System.exit(0);
    ===============The main thread===================
    This main() method calls the logindialog with username and passwrd as parameters.
    So, initially, the main() thread is started and the login dialog is displayed. On pressing Cancel in this dialog, the control goes to propertyChangeListener of the loginDialog() and calls System.exit(0) which should terminate the entire application, but at times, the previously running main thread is resumed and the application is not terminated.
    Please clarify why this happens.
    Thanks in advance!!
    });

Maybe you are looking for