Servlet release database Connection

Hi i am calling a procedure to execute from servlet , As the procedure takes quite long hours approximately 2 hours my application gets hanged for 2 hours. Also when i close my application the procedure did not run to completion but exit in between. I want my servlet to work such that when i click button to execute the procedure the procedure should run in the background without locking the application Also when i give command to execute th eprocedure and close my application the procedure should run to completion .

Can anybody suggest me how this could be achieved.

This is something like executing a job in background without locking the front end screens, and i am stuck and could not find a solution.

but here the procedure run for the first time when i start my server and run the servlet , when i run the servlet again without restarting the server the control just go to the doGet method of the servlet and the procedure do not get executed.

Please suggets me how do i execute a procedure such that the front end of the application do not get locked. also even ifi close the application the procedure should continue running.

but here the procedure run for the first time when i start my server and run the servlet , when i run the servlet again without restarting the server the control just go to the doGet method of the servlet and the procedure do not get executed.

That's because the init() method won't be called for each request, it's called only once when the container is initializing the servlet!

ruquia tabassum wrote: Please suggets me how do i execute a procedure such that the front end of the application do not get locked.

If you want to do something asynchronously in doGet(), you'll have to start the new thread in doGet()!

ruquia tabassum wrote: also even ifi close the application the procedure should continue running.

but here the procedure run for the first time when i start my server and run the servlet , when i run the servlet again without restarting the server the control just go to the doGet method of the servlet and the procedure do not get executed.

init is executed once if the servlet gets put into service, and then not again. If you want to start the thread each time someone accesses the servlet, put the code into the doGet method. Make sure to check whether there's already a thread running if you do that, so that you don't end up with multiple threads.

Please suggets me how do i execute a procedure such that the front end of the application do not get locked.

A background thread like you're trying to implement accomplishes that.

also even ifi close the application the procedure should continue running.

If by "application" you mean the web app (or the servlet container itself) then that's not possible because the thread is part of it. But production servers and application rarely get shut down, and not without planning beforehand, so that shouldn't be much of a problem.

error == ""

Don't compare string using the == operators; that's what the equals method is for.

If you're kicking off a process that runs for several hours, you should seriously consider moving that process out of the web server entirely. The Tomcat server cannot shut down until ALL threads shutdown, so if you need to restart Tomcat for any reason - even one unrelated to the app in question - you'll have to forcibly kill the entire server.

There seems to be a lot of webapps that don't know how to shutdown these days. I stumbled over another one just yesterday.

To avoid holding the webserver hostage, consider moving the long-running process to an independent executable. I had one that could run 10 hours. I made it launchable, queryable, and controllable via RMI, although other mechanisms are also possible.