-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Andrea,
On 9/29/2009 4:34 AM, aaime74 wrote: > I can cleanly stop the rendering process in almost any point of it. > The issue is not stopping it, it's detecting the client connection > was dropped. > > No matter what solution is adopted, one still depends on the ability > to detect the client has dropped the connection, something that no > one so far described how to check (I'm starting to wonder if there > is a way at all). I would do something like this, adopting Jason's strategy: private static final byte[] NOTHING = new byte[0]; public void doGet(...) { // or whatever OutputStream out = response.getOutputStream(); // look into java.util.concurrent.Executor and friends if // you've never seen them... great stuff MapDrawingTask /* implements Callable */ task = new MapDrawingTask(); Future<Void> task = executor.submit(task); while(!task.isDone() && !task.isCancelled()) { try { Thread.currentThread().sleep(100); // or whatever timeout you want } catch (InterruptedException ie) { // Ignore } try { out.write(NOTHING); out.flush(); } catch (ClientAbortException cae) { task.cancel(true); // allow interruptions // the "break" isn't strictly necessary break; // or even "return" if you want to get out quick } } if(!task.isCancelled()) { // dump output to response } } You may want to catch more exceptions than just ClientAbortException there, you might need more error handling in general, and my quick-and-dirty thread-and-task management will probably need some improvement and cleanup, but you get the general idea: the HTTP thread blocks waiting for either the map-drawing task to complete, or for the client to hang up the phone. Hope that helps, - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrCJxUACgkQ9CaO5/Lv0PDnqwCgn/WyPTUGwn6yHihzeak+HACW aOUAnR/EogE5wbVVKJUd8/aFLqXPVbYK =jXyD -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org