Multithreading hotfix #19

Merged
blizzardfinnegan merged 1 commit from devel into stable 2023-03-21 08:57:39 -04:00

View file

@ -31,8 +31,6 @@ public class Cli
*/
private static int iterationCount = 10;
private static boolean endOfCycles = false;
/**
* Scanner used for monitoring user input.
* This is a global object, so that functions
@ -135,7 +133,6 @@ public class Cli
setActiveCameras();
break;
case 5:
endOfCycles = false;
if(!camerasConfigured)
{
prompt("You have not configured the cameras yet! Are you sure you would like to continue? (y/N): ");
@ -652,22 +649,22 @@ public class Cli
final LinkedBlockingQueue<Cycle> dataEntryQueue = new LinkedBlockingQueue<>();
Thread writeThread = new Thread( () -> {
while(dataEntryQueue.size() > 0 && !endOfCycles)
ErrorLogging.logError("DEBUG: Starting write thread...");
while(true)
{
Cycle cycle = null;
do
{
try{ cycle = dataEntryQueue.poll(Long.MAX_VALUE,TimeUnit.SECONDS); }
catch(Exception e){ ErrorLogging.logError(e); }
}
while(cycle == null);
try{ cycle = dataEntryQueue.take(); }
catch(Exception e){ ErrorLogging.logError(e); }
if(cycle.getcycleNumber() == -1) break;
DataSaving.writeValues(cycle,serials);
}
ErrorLogging.logError("DEBUG: Exiting write thread.");
});
writeThread.start();
//writeThread.start();
for(int i = 0; i < localIterations; i++)
{
@ -724,8 +721,10 @@ public class Cli
}
while(fail);
dataEntryQueue.add(cycle);
if(!writeThread.isAlive())
writeThread.start();
}
endOfCycles = true;
dataEntryQueue.add(new Cycle(-1));
println("=======================================");
println("Testing complete!");
}