Eclipse: auto complete (java)

When I write code in java in Eclipse and run it a second time, the first process is still running. When, for example, I write an endless loop with some prints, run it once, and then again, it prints from both running ones, starting from the first and second. In addition, Eclipse slows down. Is there a way to automatically end the first process upon restarting?

+3
source share
4 answers

You can right-click on a record in Debug-View and select “Terminate and Relaunch”, which is closest to what you would like to have, since it will first stop the current executable instance and then start a new one with the same settings.

The other is that you are likely to implement something yourself, that is, the socket where the instance is listening and where the new one sends a shutdown command before it starts up completely.

+3
source

It seems your program is not quitting. You can exit the process with a small red square in the upper right corner of the console window.

+2
source

Short answer:

Go to Window → Show View → Debugging , select your program and end it.

Long explanation:

By describing your problem, you are probably using a framework that uses threads (do you use Swing in your game?). You can also see the current threads in the debug view.

The JVM will not terminate the process until all user threads have completed.

If you use Swing, you can use the JFrame setDefaultCloseOperation to change the default behavior of closing a window.

Or you can terminate the JVM process using System.exit (0) .

+2
source

The consensus seems to be that this is not possible. Based on the scenarios, I'm used to doing a lot of manual tests, and I like to compile the program with almost every change.

The next class (bomber) does System.exit (0) after 10 minutes. Just drop the Bomb object in Main, Bomber daBomb = new Bomber(); and run from daBomb.reset(); to reset the timer. As soon as the processes gather like flies on the windowsill, you press double X ( the "remove all terminated launches" button ) on the console tab bar to close the console of all dead processes.

 public class Bomber { Bomb bomb = new Bomb(); public Bomber() throws InterruptedException { Thread thread = new Thread(bomb); thread.start(); } public void reset() { bomb.reset(); } //kill because someone cut the redwire! public void redWire() { bomb.timer = 1000; } //Defuses bomb public void greenWire() { reset(); bomb.greenWire=false; } public class Bomb implements Runnable { public int timer; public boolean greenWire; public Bomb() { reset(); greenWire=true; } public void run() { try { while (timer > 1) { Thread.sleep(1000L); timer = timer - 1000; //System.out.println(timer); } if (greenWire) { System.exit(0); // kill, because no-one cut the green wire. } } catch (InterruptedException iex) { } } public void reset() { timer = 3000000; // five minutes // timer = 5000; // Five seconds } } } 

How thoughtfully you want to use the Bomber functionality is up to you. I created a function for Main. Please note that the following may not work perfectly, as I just pulled out a bunch of non-core code and did not test to make sure it still works.

  public static void startUp() throws InterruptedException { Bomber daBomb = new Bomber(); String input = ""; Interpreter console = new Interpreter(); while (!input.equalsIgnoreCase("quit")) { daBomb.reset(); input = terminal.next().toLowerCase(); } daBomb.redWire(); } 
+1
source

All Articles