aspose file tools*
The moose likes Servlets and the fly likes interrupt operations if session closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "interrupt operations if session closed" Watch "interrupt operations if session closed" New topic
Author

interrupt operations if session closed

Cyril Lavy
Greenhorn

Joined: Nov 18, 2003
Posts: 7
Hello,
I'm running a servlet which does some internal operations using much resources when a request is send. I have two problems: first, when someone clicks several times it sends several requests which can make the system busy for a long time, and second, if the session is closed (browser closed) or the operation is aborted on the client side, the servlet will continue to perform actions and sometimes block other users. So how can I :
- block several clicks from the same client.
- test client's existence.
- How can I declare the classes used in the operations so they can be heavily interrupted by the servlet if client's session is closed... Eternal Thanks to persons who can offer some help!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
1. The best way to block multiple clicks on the browser side is probably to use JavaScript to inactivate the link after the first click.
2. Testing that the client is still connected is harder..
2a. if you send occasional data to the response, you will get an exception if the socket connection has been closed.
2b. you can use some sort of "heartbeat" of requests evern N seconds generated by Javascript on the client's browser.
3. A long running process should be running in its own Thread, not the servlet request Thread. Usually that means a Runnable object to control the process - exactly how you tell that Thread to stop depends on what the long running process is.
Bill
Cyril Lavy
Greenhorn

Joined: Nov 18, 2003
Posts: 7
Thanks for the interest.
The problem is:
I display a list of links to my servlet, and each one generates a request that makes a document to be scanned, indexed, and this index being compared to a (sometimes huge) index object loaded in memory.
Thinking of it, the problems to disable multiple clicks and testing client existence are not so important because I can avoid them by aborting past requests before every new one (a client can abort a request by clicking on another link) or by sending a query to servlet if window is closed.
I'm beginning to make my thread separate... so I have to make another Runnable object to control it? how does this object work?
Thx.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
There have been a number of discussions here about using separate threads for long-running processes. Some searches will probably find them.
If you are just now learning about the Thread class and the Runnable interface, you should probably work in an environment that is simpler than a servlet until you have the essential functions working.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interrupt operations if session closed