• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet release database Connection

 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Any suggestion is appreciated.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start a new thread?

(Preferably using an existing job library.)
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On starting a new thread will my application do not get locked? also if i close application(logout or abrubt shutting down incase like power cut off) will the newly started thread continue execution?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the power is cut off it's highly unlikely *any* process on the machine will continue execution.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Due to the lack of power.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have designed the servlet to run the procedure ...





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.

 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ruquia tabassum wrote:

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.


By application are you referring to the browser..?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18104
51
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic