Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore System.exit() from other class

Tags:

java

Given the class below,

public class ClassOne {
    public static void main(String... args) {
        System.exit(1);
    }
}

The following class will be destroyed as well, assuming there are other things to do after ClassOne.main is invoked.

public class ClassTwo {
    public static void main(String... args) {
        ClassOne.main(args);
        Thread.sleep(30000);
    }
}

Is there a way to ignore the System.exit(1); of ClassOne in ClassTwo's invocation?

like image 269
setzamora Avatar asked Oct 27 '09 07:10

setzamora


1 Answers

You can't ignore it per se, but you can prevent it from terminating the JVM via SecurityManager. Take a look at this question for detailed code example.

like image 168
ChssPly76 Avatar answered Oct 28 '22 07:10

ChssPly76