I am currently building a small swing app to format drives and change permission and perform a bunch of small other things
Currently, I've come across an issue where running multiple processes will cause them to run asynchronously, which is awesome because it allows for me to dispatch a ton of processes quickly but for what I'm doing I need the process to wait for the one before it to finish.
The problem I've encountered is that the process.waitFor() method delays the GUI from being able to do anything (swing) until all of the processes are finished.
I'm currently using the following code structure (Which I've implemented from this answer) to deploy my commands/processes.
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
class RunSynchronously{
private static final String sudoPassword = "1234";
public static void main(String[] args) {
Process process = null;
String[] firstCmd = {"/bin/bash", "-c", "echo " + sudoPassword + "| sudo -S chmod 777 -R /media/myuser/mydrive"};
try {
process = Runtime.getRuntime().exec(firstCmd);
} catch (IOException ex) {
Logger.getLogger(Wizard_Home.class.getName()).log(Level.SEVERE, null, ex);
}
try {
process.waitFor();
} catch (InterruptedException ex) {
Logger.getLogger(Wizard_Format.class.getName()).log(Level.SEVERE, null, ex);
}
String[] secondCmd = {"/bin/bash", "-c", "echo " + sudoPassword + "| sudo -S chmod 755 -R /media/myuser/mydrive"};
try {
process = Runtime.getRuntime().exec(secondCmd);
} catch (IOException ex) {
Logger.getLogger(Wizard_Home.class.getName()).log(Level.SEVERE, null, ex);
}
try {
process.waitFor();
} catch (InterruptedException ex) {
Logger.getLogger(Wizard_Format.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
How can I delay processes or create a queue while maintaining my GUI as active and not slept/waiting?