import java.util.ArrayList;
import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.simantics.db.Session;
final private int THREADS;
final private AtomicInteger sleepers;
final private ThreadState[] threadStates;
+
+ private SessionTask currentTask;
// final private ArrayList<SessionTask>[] delayQueues;
// final private QueryThread[] executors;
// final private ReentrantLock[] threadLocks;
// lock.unlock();
try {
- exited.acquire();
+ // we are not willing to wait forever here..
+ boolean acquired = exited.tryAcquire(60, TimeUnit.SECONDS);
+ if (!acquired) {
+ LOGGER.error("Could not safely dispose query thread {} - we were processing task {} and still have tasks to do {}", index, currentTask.graph != null ? String.valueOf(currentTask) : "SessionTask with null graph", tasks.size());
+ interrupt();
+ }
} catch (InterruptedException e) {
LOGGER.error("dispose was interrupted", e);
}
while(!tasks.isEmpty()) {
- SessionTask task = tasks.remove(tasks.size() - 1);
+ SessionTask t = currentTask = tasks.remove(tasks.size() - 1);
// if(task.syncCaller == index) {
// ownSyncTasks[index].add(task);
// } else {
- task.run(index);
+ t.run(index);
// System.err.println("QT(s) " + index + " runs " + task);
didExecute = true;
+ currentTask = null;
// }
}
while(!tasks.isEmpty()) {
- SessionTask task = tasks.remove(tasks.size()-1);
+ SessionTask t = currentTask = tasks.remove(tasks.size()-1);
// System.err.println("QT " + index + " runs " + task);
- task.run(index);
-
+ t.run(index);
+ currentTask = null;
}
// for(int performer=0;performer<THREADS;performer++) {
} catch (Throwable e) {
- e.printStackTrace();
+ LOGGER.error("Could not perform write only for request {}", request, e);
releaseWriteOnly(writeState.getGraph());
// Serialize as '<resource index>_<cluster id>'
return "" + r + "_" + getCluster(resourceImpl);
} catch (Throwable e) {
- e.printStackTrace();
+ LOGGER.error("Could not create random access id for resource {}", resource, e);
throw new InvalidResourceReferenceException(e);
} finally {
}
} catch (NumberFormatException e) {
throw new InvalidResourceReferenceException(e);
} catch (Throwable e) {
- e.printStackTrace();
+ LOGGER.error("Could not get resource for randomAccessId {}", randomAccessId, e);
throw new InvalidResourceReferenceException(e);
} finally {
}
}
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOGGER.error("Acquiring was interrupted", e);
// FIXME: Should perhaps do something else in this case ??
}
}