public ModificationQueue finishTx() { final TransactionReference tx = transactions.get(); ModificationQueue modificationQueue = null; if (tx != null) { if (tx.isToplevel()) { modificationQueue = queues.get(); final Set<String> synchronizationKeys = modificationQueue.getSynchronizationKeys(); // cleanup queues.remove(); buffers.remove(); currentCommand.remove(); transactions.remove(); try { tx.close(); } catch (Throwable t) { t.printStackTrace(); } finally { // release semaphores as the transaction is now finished semaphore.release(synchronizationKeys); // careful: this can be null } } else { tx.end(); } } return modificationQueue; }