TransactionManager { public TransactionManager() { final File dir = new File("data"); dir.mkdirs(); timer = new Timer("TransactionTimeoutThread", false); timer.schedule(new TimerTask() { @Override public void run() { lock.lock(); try { long start = System.currentTimeMillis(); for (File file : dir.listFiles()) { try (BufferedReader in = new BufferedReader(new FileReader(file))) { String line = in.readLine(); long timestamp = Long.parseLong(line); long now = System.currentTimeMillis(); if (timestamp + now > TIMEOUT) { file.delete(); } } catch (IOException e) { file.delete(); } } long stop = System.currentTimeMillis(); System.out.printf("Time: %d%n", stop - start); } finally { lock.unlock(); } TransactionManager.this.notifyAll(); } }, 0, 30000); } TransactionManager(); void stop(); Transaction allocateTransaction();  }
@Test public void testTransactionManager() throws Exception { TransactionManager manager = new TransactionManager(); Thread.sleep(60000); }