class CloseableWorkerThread extends WorkerThread implements Closeable {

	@Override
	public synchronized void close() throws IOException {
		if (m_closeable == null) {
			return;
		}
		
		T t = m_closeable;
		m_closeable = null;
		
		/*
		 * Some closeable classes like PipedInputStream will block forever
		 * in a read() method even if we close the stream. Therefore we need
		 * to interrupt the thread. Note that at least PipedInputStream
		 * will fail to read if the stream is closed so there may not be a
		 * racing condition here.
		 */
		if (state() == WtState.RUNNING) {
			thread().interrupt();
		}
		
		try {
			t.close();
		} finally {
			m_dispatcher.dispatch(new DispatcherOp<CloseableListener>() {
				@Override
				public void dispatch(CloseableListener l) {
					l.closed(null);
				}
			});
		}
	}

	public  CloseableWorkerThread(String name, T closeable,
			boolean close_on_abort);

}