void () { while (true) { final Runnable stuff; synchronized (myLock) { stuff = myQueue.poll(); if (stuff == null) { // queue is empty, stop progress myActive = false; return; } } // each task is executed only once, once it has been taken from the queue.. try { stuff.run(); } catch (ProcessCanceledException ignored) { } catch (Throwable t) { LOG.warn(t); } } }