• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet release database Connection

 
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic