jar - Program dismisses steps when running quickly (Java) -


i running tool runs external java program several times in operation. external tool starts opening joptionpane inside jframe.

here test script wrote try solve issue.

import java.io.file;  public class test {     public static void main(string[] args) throws exception {          for(int i=0; i<6; i++) {             //thread.sleep(1000);              string torun = "java -jar \"" + "c:\\folder\\file.jar" + "\" " + i;              runtime.getruntime().exec(torun, null, new file("c:\\folder"));         }     } } 

when runs, final run's joptionpane (i=5) appears, seems others "trying" appear panes seem opening , closing.

when uncomment thread.sleep however, of panes open separately. if set sleep 300 (0.3 seconds) half of panes appear, first , last ones.

i find way run instances of external program without needing use thread.sleep() @ all, if possible.

edit: per requirement's i've minimalised external program well.

import java.nio.file.files; import java.nio.file.path; import java.nio.file.paths; import java.text.simpledateformat; import java.util.date;  import javax.swing.jframe; import javax.swing.joptionpane;  public class file {     static jframe frame = new jframe("frame");     private static string doc1address = "c:\\folder\\doc1.csv";     private static string doc2address = "c:\\folder\\doc2.csv";       public static void main(string[] args) throws exception {         if(args.length == 1) {              simpledateformat form = new simpledateformat("yyyy-mm-dd hh-mm-ss");             date date = new date();             string currentdate = form.format(date);              //save backup of doc1             string doc1backaddress = doc1log.substring(0, doc1log.length()-15) + "doc1back " + currentdate + ".csv";             path todoc1 = paths.get(doc1address);             path todoc1back = paths.get(doc1backaddress);             files.copy(todoc1, todoc1back);             files.setattribute(todoc1back, "dos:readonly", true);              //save backup of doc2             string doc2backaddress = doc2log.substring(0, doc2log.length()-16) + "doc2back " + currentdate + ".csv";             path todoc2 = paths.get(doc2address);             path todoc2back = paths.get(doc2backaddress);             files.copy(todoc2, todoc2back);             files.setattribute(todoc2back, "dos:readonly", true);              //format jframe             frame.pack();             frame.setlodoc1ionrelativeto(null);             frame.setvisible(true);             frame.setdefaultcloseoperation(jframe.dispose_on_close);              joptionpane.showmessagedialog(frame, args[0]);             frame.dispose();         }     } } 

found own issue; since backup files use format yyyy-mm-dd hh-mm-ss, , files saved during same second result in filealreadyexists exception, meaning first file finish saving allows program continue running.

having 1 second pause results in files having different save names, no error occurs.

having sub-1 second pause results in file name overlap, different names too, hence files appear.

solution: either change name format (i.e. include milliseconds), or include backup functions in if-statement, ignored if file same time exists.

(also; thank @erwinbolwidt, in being encouraged format question realised issue in code not assumed be).


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -