[concurrency-interest] Example using TimedCallable with PooledExecutor

Michael Mattox michael.mattox@verideon.com
Fri, 6 Jun 2003 17:31:30 +0200


I'm using a PooledExecuter but sometimes my threads hang forever and I want
to add a timeout.  I looked at the TimedCallable class but it's not clear
how to use it for my particular example (I tried the example in the
FutureResult class).  Can someone give me a hint on how to use this?

	private boolean addMonitorToQueue(String monitorId) {
		boolean success = false;
		DispatcherThread thread;
		try {
			thread = new DispatcherThread(monitorId);
			if (!queue.contains(thread)) {
				try {
					pool.execute(thread);
					success = true;
					log.debug("Added monitor " + monitorId + " to the queue.");
				} catch (InterruptedException e) {
					log.error("Could not add thread for monitor " + monitorId + " : ", e);
				}
			} else {
				log.debug("Did not add monitor " + monitorId + " to the queue because
it's already in the queue. ");
			}
		} catch (TechnicalException e) {
			log.error("Could not dispatch thread for monitor: " + monitorId, e);
		}
		return success;
	}

Thanks!
Michael