use of org.apache.commons.lang3.concurrent.ConcurrentRuntimeException in project GDSC-SMLM by aherbert.
the class FitEngine method end.
/**
* Signal that no more fitting work will be added to the queue.
*
* <p>Ask all threads to end and wait. Returns when all threads have stopped running.
*
* @param now Stop the work immediately, otherwise finish all work in the queue
* @throws ConcurrentRuntimeException if interrupted while waiting to add.
*/
public synchronized void end(boolean now) {
if (threads.isEmpty()) {
return;
}
time = 0;
if (now) {
// Request worker shutdown
for (final FitWorker worker : workers) {
worker.finish();
}
// If there are already jobs then the worker will stop due to the finish() signal.
for (int i = 0; i < threads.size(); i++) {
// non-blocking add to queue
if (!jobs.offer(EMPTY_JOB)) {
// At capacity so stop adding more
break;
}
}
} else {
// Finish all the worker threads by passing in a null job
for (int i = 0; i < threads.size(); i++) {
// blocking add to queue
put(EMPTY_JOB);
}
}
// Collect all the threads
for (int i = 0; i < threads.size(); i++) {
try {
threads.get(i).join();
time += workers.get(i).getTime();
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Unexpected interruption", ex);
throw new ConcurrentRuntimeException(ex);
}
}
// Output this to the log
if (counter != null) {
// Get the stats we want...
// Note: The total localisations may be less than 'fit single' + 2 * 'fit doublet':
// - Duplicates are eliminated from the results
// - Doublet fitting may result in excluded spots due to bad shifts, fitting an existing
// result or fitting a candidate which creates an estimate for re-use when the candidate
// is processed.
// System.out.println(results.getName()); // Dataset name
logger.info("Fitting paths...");
final int total = counter.getTotal();
final int single = counter.getUnset(FitType.MULTI);
report("Single", single, total);
report("Multi", total - single, total);
final int ok = counter.getSet(FitType.OK);
report("OK", ok, total);
report("Fail", total - ok, total);
final int multi = total - single;
report("FailSingle", counter.getUnset(FitType.OK | FitType.MULTI), single);
report("FailMulti", counter.get(FitType.MULTI, FitType.OK), multi);
report("FitSingle", counter.get(FitType.OK, FitType.MULTI), ok);
report("FitSingleSingle", counter.get(FitType.OK, FitType.MULTI | FitType.DOUBLET_OK), ok);
report("FitSingleDoublet", counter.get(FitType.DOUBLET_OK, FitType.MULTI), ok);
report("FitMulti", counter.getSet(FitType.OK | FitType.MULTI), ok);
report("FitMultiSingle", counter.getSet(FitType.MULTI_OK), ok);
report("FitMultiDoublet", counter.getSet(FitType.MULTI_DOUBLET_OK), ok);
report("FailMultiFitSingle", counter.get(FitType.OK | FitType.MULTI, FitType.MULTI_OK | FitType.MULTI_DOUBLET_OK | FitType.DOUBLET_OK), ok);
report("FailMultiFitDoublet", counter.get(FitType.OK | FitType.MULTI | FitType.DOUBLET_OK, FitType.MULTI_OK | FitType.MULTI_DOUBLET_OK), ok);
}
threads.clear();
}
Aggregations