> Just fscking don't. And JSPs don't have buttons to
> click. HTML files do. And the request should go to a
> servlet, which then triggers whichever business logic
> you need.
>
It is understood that... JSPs don't have buttons to click. I am talking abt the page form which i wan to call the thread....
> You don't need a thread anywhere.
ya i know it is possible to do that without using thread...
since the operation will takes lot of time do the req operation... i want to do that within a thread....
I suppose your case is like this:
- click button
- send request
- start thread
- return response
- still execute thread
- finish thread
So what happens if something goes wrong in the part after you returned the response? How will you notify your client?
You probably need some kind of background job management system. I'd recomend using one thread for the whole web-app and queue synchronize requests on it. This prevents a lot of heavy database activities happening at once (which would almost certainly cost you overall throughput).
Use a ContextListener to create the queue (probably a LinkedBlockingQueue) and start the service thread. The contextDestroyed method interrupts the thread and shuts it down. The listener puts the queue object into the application context attributes so the servlet can find it.
Your servlet adds an item to the queue (an Object specifying synchronization details), and if the service thread isn't busy that wakes it up.
Alternatively you can use a ThreadPoolExecutor (which does essentially the same thing). It's probably OTT though, and prevents extra refinements, like openning a connection and keeping it open until there's nothing on the queue (use poll()).
You need to think though, about whether the user needs to be able to find out if his job is complete, and how you will manage that. Perhaps you want to place your queue entry in session and including an outcome status field in it.
ps
You may want to think about serializing the request list to a file when the web app closes, and reloading it when it opens.
Message was edited by:
malcolmmc