[jcifs] jTDS + jCIFS works!

Michael B Allen mba2000 at ioplex.com
Thu Jul 22 18:12:03 GMT 2004


On Thu, 22 Jul 2004 09:00:48 -0500
ddkilzer at kilzer.net (David D. Kilzer) wrote:

> does.  When it receives an InterruptedIOException after setting the
> socket timeout, it immediately creates a "cancel" packet and sends it to
> the server.

If there is a "cancel" packet then the solution is relatively straight
forward. Create a watch dog thread with which you can register requests
that can be canceled. In the run loop compute the next timeout and wait(
timeout ). If in that time the request is returned call unregister( req
) and no cancel will be sent. If unregister is not called, the wait(
timeout ) will expire, req.expiration < now will be true and a cancel
will be sent.

Rough code follows:

class Request {
	OutputStream out;
	long expiration;

	/* other stuff used to maintain state of a query or request to the server
	 * that can be cancelled */
}

class CancelThread extends Thread {

	LinkedList requests = new LinkedList();

	synchronized void register( Request req ) {
		request.add( req );
		notify();
	}
	synchronized void unregister( Request req ) {
		requests.remove( req );
		notify();
	}

	public void run() {
		synchronized( this ) {
			for( ;; ) {
				long expiration = Long.MAX_VALUE;
				long now = System.currentTimeMillis();
	
				ListIterator li = queries.listIterator();
				while (li.hasMore()) {
					Request req = li.next();
	
					if( req.expiration < now ) {
						requests.remove( req );
						writeCancelPacket( req );
					} else if( req.expiration < expiration ) {
						expiration = req.expiration;
					}
				}

				wait( expiration );
			}
		}
	}
}

-- 
Greedo shoots first? Not in my Star Wars.


More information about the jcifs mailing list