/** * Reset the time limit to 0. Only the thread who initiated the latest time limit can also take it back. If another thread * tries to reset the time limit, it is ignored. */ public synchronized void resetTimeLimit() { if (customer == Thread.currentThread()) { // whoever set the time limit doResetTimeLimit(); notify(); } // Any other thread trying to reset the time limit // is ignored. }
/** * Reset the time limit to 0. Only the thread who initiated the latest time limit can also take it back. If another thread * tries to reset the time limit, it is ignored. */ public synchronized void resetTimeLimit() { if (customer == Thread.currentThread()) { // whoever set the time limit doResetTimeLimit(); notify(); } // Any other thread trying to reset the time limit // is ignored. }
public void run() { while (true) { Thread orderingCustomer = getCustomer(); if (orderingCustomer == null) { logger.info("Waiting for timer request."); } else { logger.info("Received timer request: " + getTimeLimit() + " ms."); } doWait(getTimeLimit()); if (shouldExit()) { logger.info("Exiting."); return; } if (getCustomer() == null) { // timer was reset before timeout logger.info("Normal operation, timer stopped."); } else if (getCustomer() == orderingCustomer) { logger.info("Timeout occurred. Destroying Process."); // OK, the serious case doDestroy(); doResetTimeLimit(); } // Else, a different customer. Just forget about old request, // and deal with new one. } } }
public void run() { while (true) { Thread orderingCustomer = getCustomer(); if (orderingCustomer == null) { logger.info("Waiting for timer request."); } else { logger.info("Received timer request: " + getTimeLimit() + " ms."); } doWait(getTimeLimit()); if (shouldExit()) { logger.info("Exiting."); return; } if (getCustomer() == null) { // timer was reset before timeout logger.info("Normal operation, timer stopped."); } else if (getCustomer() == orderingCustomer) { logger.info("Timeout occurred. Destroying Process."); // OK, the serious case doDestroy(); doResetTimeLimit(); } // Else, a different customer. Just forget about old request, // and deal with new one. } } }
/** * Reset the time limit to 0. Only the thread who initiated the latest time limit can also take it back. If another thread * tries to reset the time limit, it is ignored. */ public synchronized void resetTimeLimit() { if (customer == Thread.currentThread()) { // whoever set the time limit doResetTimeLimit(); notify(); } // Any other thread trying to reset the time limit // is ignored. }
public void run() { while (true) { Thread orderingCustomer = getCustomer(); if (orderingCustomer == null) { logger.info("Waiting for timer request."); } else { logger.info("Received timer request: " + getTimeLimit() + " ms."); } doWait(getTimeLimit()); if (shouldExit()) { logger.info("Exiting."); return; } if (getCustomer() == null) { // timer was reset before timeout logger.info("Normal operation, timer stopped."); } else if (getCustomer() == orderingCustomer) { logger.info("Timeout occurred. Destroying Process."); // OK, the serious case doDestroy(); doResetTimeLimit(); } // Else, a different customer. Just forget about old request, // and deal with new one. } } }