So instead of "sleeping" a thread, as in Thread.sleep();
to merely allow the processes to run on another thread and make the new thread sleep with Thread.sleep();
but not the original Thread
. Is this possible?
Here is my method that I want to run on a new Thread
called processesThread
:
private void Processes() throws IOException, InterruptedException {
// New Thread "processesThread" will start here.
Runtime rt = Runtime.getRuntime();
List<Process> processes = new ArrayList<Process>();
// "runnableTogether" will be the number that the user inputs in the GUI.
switch (runnableTogether) {
case 4:
processes.add(rt.exec("C:/Windows/System32/SoundRecorder.exe"));
case 3:
processes.add(rt.exec("C:/Windows/System32/taskmgr.exe"));
case 2:
processes.add(rt.exec("C:/Windows/System32/notepad.exe"));
case 1:
processes.add(rt.exec("C:/Windows/System32/calc.exe"));
Thread.sleep(5000);
destroyProcesses(processes);
break;
default:
System.exit(0);
break;
}
// New Thread "processesThread" will end here.
}
Is this possible? And if so, how?
I have researched starting new Threads
, but I can't quite figure out how to get it to work with my program.
EDIT: I was hoping to use something similar to this approach:
Thread processesThread = new Thread() {
public void run() {
// Code here.
}
};
processesThread.start();
Any ideas?