简体   繁体   中英

Terminating Eclipse console using Java Code

Is there a way of terminating the eclipse console by writing a java code rather than pressing on the red button in the console. I have tried to read online regarding this, could not find something sensible.

Some programmers suggest the use of System.out.flush()... did not work.

Thank you

System.out.flush() does a completely different thing - it doesn't terminate the current process, but flushes the OutputStream of the System class.

You can try with this statement:

System.exit(0);

It's javadoc says

Terminates the currently running Java Virtual Machine.

which I believe is the thing you need.

Please, before using the System.exit() method, get familiar with what the javadoc states.

Clicking the red button in the Console sends a signal to the currently running JVM to terminate. As a result of this, your Java Application will terminate as well.

To terminate your Java Program and the JVM behind it, you have two options:

  1. Call System.exit(0) or with any other exit code (insteaf of 0) - this will lead the JVM to terminate with the given exit code
  2. Terminate all currently running Java Threads. If no Java Thread is running anymore (eg your main -Method finished without starting another thread), the JVM will terminate with exit value 0.

After your program isn't running anymore, Eclipse will display your program as terminated and disable the red button in the Console.

And System.out.flush() hasn't anything to do with this ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM