boolean pending = true; long start = System.currentTimeMillis(); long now; while (pending) { try { Thread.sleep(5000); } catch (InterruptedException ignore) { // ignore } now = System.currentTimeMillis(); if (now - start > 60000) { throw new Exception(""); } }