What will happen if I call System.exit() while have some runningthreads?

E

Evol

Will the data modified by another thread remain an unconscious state?
For example, if one thread is connecting with database and I call
System.exit() in another thread, I guess the operation with database
will finish before vm exit. Is that true?
 
J

jolz

System.exit() is an immediate kill-the-JVM, stop-the-world.

Very often it is but it doesn't have to be:

public class Test {
public static void waitForSomething() {
try {
Thread.sleep(1000000);
} catch (Exception ex) { }
}

public static void main(String[] args) {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
waitForSomething();
}
});

System.exit(0);
}
}

Obviously no one should do this without a very good reason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top