Added closing and re-opening functionality to Parallel.
@@ -65,6 +65,10 @@ public final class Parallel {
// Static only.
private Parallel() {}
+ public synchronized static void close() {
+ shutdown();
+ }
+
public synchronized static int getNumThreads() {
if (numThreads == -1) {
numThreads = Options.PARALLEL_NUM_THREADS.getInt();
@@ -305,6 +309,10 @@ public final class Parallel {
}
private static void shutdown() {
+ if (!initialized) {
+ return;
+ }
+
cleanupWorkers();
try {
@@ -313,10 +321,18 @@ public final class Parallel {
} catch (InterruptedException ex) {
// Do nothing, we are shutting down anyways.
}
+ pool = null;
+ threadObjects.clear();
+
+ workerQueue.clear();
workerQueue = null;
+
+ allWorkers.clear();
allWorkers = null;
- pool = null;
+
+ numThreads = -1;
+ initialized = false;
}
/**
