void () { while (true) { if (myProgressIndicator != null && (myProgressIndicator.isCanceled() || !myProgressIndicator.isRunning()) || cancelableFun != null && cancelableFun.getAsBoolean() || processHandler.isProcessTerminated()) { if (!processHandler.isProcessTerminated()) { try { processHandler.destroyProcess(); } finally { mySemaphore.up(); } } break; } try { synchronized (this) { wait(1000); } } catch (InterruptedException e) { //Do nothing } } }