This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interrupt operations if session closed

 
Cyril Lavy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic