Multithreading hotfix
Write thread was prematurely exiting in previous build
This commit is contained in:
parent
8be83fa479
commit
ac90cd02ae
1 changed files with 11 additions and 12 deletions
|
@ -31,8 +31,6 @@ public class Cli
|
||||||
*/
|
*/
|
||||||
private static int iterationCount = 10;
|
private static int iterationCount = 10;
|
||||||
|
|
||||||
private static boolean endOfCycles = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scanner used for monitoring user input.
|
* Scanner used for monitoring user input.
|
||||||
* This is a global object, so that functions
|
* This is a global object, so that functions
|
||||||
|
@ -135,7 +133,6 @@ public class Cli
|
||||||
setActiveCameras();
|
setActiveCameras();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
endOfCycles = false;
|
|
||||||
if(!camerasConfigured)
|
if(!camerasConfigured)
|
||||||
{
|
{
|
||||||
prompt("You have not configured the cameras yet! Are you sure you would like to continue? (y/N): ");
|
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<>();
|
final LinkedBlockingQueue<Cycle> dataEntryQueue = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
Thread writeThread = new Thread( () -> {
|
Thread writeThread = new Thread( () -> {
|
||||||
while(dataEntryQueue.size() > 0 && !endOfCycles)
|
ErrorLogging.logError("DEBUG: Starting write thread...");
|
||||||
|
while(true)
|
||||||
{
|
{
|
||||||
Cycle cycle = null;
|
Cycle cycle = null;
|
||||||
|
|
||||||
do
|
try{ cycle = dataEntryQueue.take(); }
|
||||||
{
|
|
||||||
try{ cycle = dataEntryQueue.poll(Long.MAX_VALUE,TimeUnit.SECONDS); }
|
|
||||||
catch(Exception e){ ErrorLogging.logError(e); }
|
catch(Exception e){ ErrorLogging.logError(e); }
|
||||||
}
|
|
||||||
while(cycle == null);
|
if(cycle.getcycleNumber() == -1) break;
|
||||||
|
|
||||||
DataSaving.writeValues(cycle,serials);
|
DataSaving.writeValues(cycle,serials);
|
||||||
}
|
}
|
||||||
|
ErrorLogging.logError("DEBUG: Exiting write thread.");
|
||||||
});
|
});
|
||||||
|
|
||||||
writeThread.start();
|
//writeThread.start();
|
||||||
|
|
||||||
for(int i = 0; i < localIterations; i++)
|
for(int i = 0; i < localIterations; i++)
|
||||||
{
|
{
|
||||||
|
@ -724,8 +721,10 @@ public class Cli
|
||||||
}
|
}
|
||||||
while(fail);
|
while(fail);
|
||||||
dataEntryQueue.add(cycle);
|
dataEntryQueue.add(cycle);
|
||||||
|
if(!writeThread.isAlive())
|
||||||
|
writeThread.start();
|
||||||
}
|
}
|
||||||
endOfCycles = true;
|
dataEntryQueue.add(new Cycle(-1));
|
||||||
println("=======================================");
|
println("=======================================");
|
||||||
println("Testing complete!");
|
println("Testing complete!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue