@Override public void run() { try { // always set this.alive before stopping while (isAlive()) { try { // handle handle exceptions Thread.sleep(SLEEP_MILLIS); if (this.file.exists()) { try { // always check stopAfterRequest after main work work(); } finally { if (this.stopAfterRequest) { stopMe(); } } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); // allow to loop around and check isAlive() } catch (IOException e) { logger.error("Unable to control process with {}. Please add tools.jar from JDK to classpath for improved process control.", this.file); // allow to loop around and check isAlive() } } } finally { synchronized (this) { this.alive = false; } } }
@Override public void run() { try { // always set this.alive before stopping while (isAlive()) { try { // handle handle exceptions Thread.sleep(SLEEP_MILLIS); if (this.file.exists()) { try { // always check stopAfterRequest after main work work(); } finally { if (this.stopAfterRequest) { stopMe(); } } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); // allow to loop around and check isAlive() } catch (IOException e) { ControllableProcess.getOrCreateLogWriter().error("Unable to control process with " + this.file + ". Please add tools.jar from JDK to classpath for improved process control."); // allow to loop around and check isAlive() } } } finally { synchronized (this) { this.alive = false; } } }