I have a multi-threaded compiler developed in Java. It receives n filepaths and starts one thread for each filepath received.
Everything works fine if I do multiple executions with a single file. However, when I input multiple files and execute it one time per second it shows different parsing outputs in the source-code loaded.
It was implemented using the recursive descent parser technique. The function that calls the threads is shown as follows:
public static void main(String[] args) {
if(args.length == 0){
System.out.println("No file path informed. Please inform file paths.");
System.out.println("Usage: java -jar KPiler.jar file1.txt file2.txt");
}
List<String> paths = new ArrayList<>();
List<String> errorMessages = new ArrayList<>();
List<Parser> compileJobs = new ArrayList<>();
paths.addAll(Arrays.asList(args));
while(paths.size() > 0 || compileJobs.size() > 0){
if(compileJobs.size() < MAX_JOBS && paths.size() > 0){
compileJobs.add(new Parser(paths.remove(0)));
compileJobs.get(compileJobs.size() -1).start();
}
for(int i=0 ; i<compileJobs.size(); i++){
if(!compileJobs.get(i).isAlive()){
errorMessages.add(compileJobs.get(i).getErrorMessages());
compileJobs.remove(i);
}
}
}
//PRINTING OUTPUT
for(int i = 0; i<errorMessages.size(); i++){
System.out.println(errorMessages.get(i));
}
}
Does it have to do with multiple file accesses?