void start() { synchronized (this) { if (this.thread == null) { this.thread = new Thread(this, createThreadName()); this.thread.setDaemon(true); this.alive = true; this.thread.start(); } } }
@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; } } }
public void stop() { try { this.statusRequestFileWatchdog.stop(); } catch (InterruptedException e) { logger.warn("Interrupted while stopping status handler for controllable process.", e); } finally { try { this.stopRequestFileWatchdog.stop(); } catch (InterruptedException e) { logger.warn("Interrupted while stopping stop handler for controllable process.", e); } this.launcher.close(); } }
final ControlFileWatchdog statusFileWatchdog = new ControlFileWatchdog(workingDir, statusFileName, statusHandler, true); statusFileWatchdog.start(); while (statusFileWatchdog.isAlive()) { Thread.sleep(10); if (System.currentTimeMillis() >= start + this.statusTimeoutMillis) { final TimeoutException te = new TimeoutException("Timed out waiting for process to create " + statusFile); try { statusFileWatchdog.stop(); } catch (InterruptedException e) { logger.info("Interrupted while stopping status file watchdog.", e);
this.stopRequestFileWatchdog = new ControlFileWatchdog(workingDir, processType.getStopRequestFileName(), stopHandler, false); this.stopRequestFileWatchdog.start(); this.statusRequestFileWatchdog = new ControlFileWatchdog(workingDir, processType.getStatusRequestFileName(), statusHandler, false); this.statusRequestFileWatchdog.start();
final ControlFileWatchdog statusFileWatchdog = new ControlFileWatchdog(workingDir, statusFileName, statusHandler, true); statusFileWatchdog.start(); while (statusFileWatchdog.isAlive()) { Thread.sleep(100); if (System.currentTimeMillis() >= start + this.statusTimeout) { final TimeoutException te = new TimeoutException("Timed out waiting for process to create " + statusFile); try { statusFileWatchdog.stop(); } catch (InterruptedException e) { ControllableProcess.getOrCreateLogWriter().info("Interrupted while stopping status file watchdog.", e);
this.stopRequestFileWatchdog = new ControlFileWatchdog(workingDir, processType.getStopRequestFileName(), stopHandler, false); this.stopRequestFileWatchdog.start(); this.statusRequestFileWatchdog = new ControlFileWatchdog(workingDir, processType.getStatusRequestFileName(), statusHandler, false); this.statusRequestFileWatchdog.start();
@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; } } }
void start() { synchronized (this) { if (this.thread == null) { this.thread = new Thread(this, createThreadName()); this.thread.setDaemon(true); this.alive = true; this.thread.start(); } } }
public void stop() { try { this.statusRequestFileWatchdog.stop(); } catch (InterruptedException e) { getOrCreateLogWriter().warning("Interrupted while stopping status handler for controllable process.", e); } finally { try { this.stopRequestFileWatchdog.stop(); } catch (InterruptedException e) { getOrCreateLogWriter().warning("Interrupted while stopping stop handler for controllable process.", e); } this.launcher.close(); } }