| | |
Stopping a very time consuming class method's execution on tomcat server using JSP.
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2006
Posts: 2
Reputation:
Solved Threads: 0
Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#1 Feb 27th, 2006
Hey all,
I have a very strange problem and expecting to receive your answer very urgent...
I have a class in my package named MyPackage on my tomcat server. I am using one method of this class, which is very time consuming, as follows in my jsp page...
HeavyClass hc = new HeavyClass();
hc.methodLongTimeExecution();
once I press submit button in my jsp page, it will start execution of this method on the server, and will execute for longer time. meanwhile, as this process is very timeconsuming, when a user clicks Stop button, my browser will stop responding, but the execution of the method will still continue on my Tomcat Server. Now, because, this method execution requires very heavy memory as well as it takes very long time, what I want is, whenever a person clicks a stop button of browser, it should also stop the execution of that method on my remote tomcat server.
Can anyone guide me how can I do this???
or also, guide me about what I should do if I want to put my own button to stop the execution, and how can stop execution of the method on click of that button...
I need the answer very urgently...
Kindly reply soon,
Thanking you,
Nihar.
I have a very strange problem and expecting to receive your answer very urgent...
I have a class in my package named MyPackage on my tomcat server. I am using one method of this class, which is very time consuming, as follows in my jsp page...
HeavyClass hc = new HeavyClass();
hc.methodLongTimeExecution();
once I press submit button in my jsp page, it will start execution of this method on the server, and will execute for longer time. meanwhile, as this process is very timeconsuming, when a user clicks Stop button, my browser will stop responding, but the execution of the method will still continue on my Tomcat Server. Now, because, this method execution requires very heavy memory as well as it takes very long time, what I want is, whenever a person clicks a stop button of browser, it should also stop the execution of that method on my remote tomcat server.
Can anyone guide me how can I do this???
or also, guide me about what I should do if I want to put my own button to stop the execution, and how can stop execution of the method on click of that button...
I need the answer very urgently...
Kindly reply soon,
Thanking you,
Nihar.
Re: Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#2 Mar 1st, 2006
Well, you could write a stop method and rewrite the "start" method to use
threads, then after you instantiate the class, store it as a session variable, then
start the "start" method as a thread. Then return a page containing the key used
to store the object and stop button. The stop button will call another jsp that
will retreive the object stored under that key and call the "stop" method. This is
all really loosely explained, but you should be able to extrapolate from here.
Unfortunately, your user will also get no notification that the process is finished.
You could, however, write a checkProgress method that another jsp can use to check the process and "refreshes" from time to time. This would have to called
using a refresh from the "stop button" page and also then must contain the "stop
button".
threads, then after you instantiate the class, store it as a session variable, then
start the "start" method as a thread. Then return a page containing the key used
to store the object and stop button. The stop button will call another jsp that
will retreive the object stored under that key and call the "stop" method. This is
all really loosely explained, but you should be able to extrapolate from here.
Unfortunately, your user will also get no notification that the process is finished.
You could, however, write a checkProgress method that another jsp can use to check the process and "refreshes" from time to time. This would have to called
using a refresh from the "stop button" page and also then must contain the "stop
button".
•
•
Join Date: Feb 2006
Posts: 2
Reputation:
Solved Threads: 0
Re: Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#3 Mar 1st, 2006
Hi masijade,
Thanks for your suggestion. It really worked. I implemented it and it is working fine...
Really thanks for your kindness.
--> Nihar Dhruva.
Thanks for your suggestion. It really worked. I implemented it and it is working fine...
Really thanks for your kindness.
--> Nihar Dhruva.
•
•
•
•
Originally Posted by masijade
Well, you could write a stop method and rewrite the "start" method to use
threads, then after you instantiate the class, store it as a session variable, then
start the "start" method as a thread. Then return a page containing the key used
to store the object and stop button. The stop button will call another jsp that
will retreive the object stored under that key and call the "stop" method. This is
all really loosely explained, but you should be able to extrapolate from here.
Unfortunately, your user will also get no notification that the process is finished.
You could, however, write a checkProgress method that another jsp can use to check the process and "refreshes" from time to time. This would have to called
using a refresh from the "stop button" page and also then must contain the "stop
button".
Re: Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#4 Mar 1st, 2006
•
•
Join Date: Apr 2006
Posts: 1
Reputation:
Solved Threads: 0
Re: Stopping a very time consuming class method's execution on tomcat server using JS
0
#5 Apr 26th, 2006
Hi there masijade.
Would you care to explain a little bit further what you're saying, I have the same problem but I don't understand your soultion.
Thanx for your time.
coltech
Would you care to explain a little bit further what you're saying, I have the same problem but I don't understand your soultion.
Thanx for your time.
coltech
•
•
•
•
Originally Posted by masijade
Well, you could write a stop method and rewrite the "start" method to use
threads, then after you instantiate the class, store it as a session variable, then
start the "start" method as a thread. Then return a page containing the key used
to store the object and stop button. The stop button will call another jsp that
will retreive the object stored under that key and call the "stop" method. This is
all really loosely explained, but you should be able to extrapolate from here.
Unfortunately, your user will also get no notification that the process is finished.
You could, however, write a checkProgress method that another jsp can use to check the process and "refreshes" from time to time. This would have to called
using a refresh from the "stop button" page and also then must contain the "stop
button".
Re: Stopping a very time consuming class method's execution on tomcat server using JS
0
#6 May 2nd, 2006
Sorry, I was away.
Well, what I am saying goes as follows:
the long running process should be contained in its own object rather than
being called directly from the jsp. Also, creating an instance of this
object should not start the process, but just create a "handle" to it. This
object should have "start", "stop", and "checkProgress" methods. The
start method should start the long running process in a thread. The stop
method should interupt this thread and perform and needed cleanup. The
checkProgress method should report back how far the process has
progressed (how you do/report/track this is completely up to you).
Now on to usage:
In initial JSP:
- create instance
- store instance as session object
- call instance start routine
- return an html page containing a "stop" link (url to "stop" page")
- this page will (after a set time) refresh to the "checkProgress" page
use the refresh header info for this
In refresh jsp:
- retrieve instance from session
- call the checkProgress method
- return an html page that will refresh to itself after a set time
use the refresh header info for this
- this page should also contain the "stop" link (url to the "stop" page)
In Stop page:
- retrieve instance from session
- call "stop" method
- delete the session object
- return an acknowledgement html page
Well, what I am saying goes as follows:
the long running process should be contained in its own object rather than
being called directly from the jsp. Also, creating an instance of this
object should not start the process, but just create a "handle" to it. This
object should have "start", "stop", and "checkProgress" methods. The
start method should start the long running process in a thread. The stop
method should interupt this thread and perform and needed cleanup. The
checkProgress method should report back how far the process has
progressed (how you do/report/track this is completely up to you).
Now on to usage:
In initial JSP:
- create instance
- store instance as session object
- call instance start routine
- return an html page containing a "stop" link (url to "stop" page")
- this page will (after a set time) refresh to the "checkProgress" page
use the refresh header info for this
In refresh jsp:
- retrieve instance from session
- call the checkProgress method
- return an html page that will refresh to itself after a set time
use the refresh header info for this
- this page should also contain the "stop" link (url to the "stop" page)
In Stop page:
- retrieve instance from session
- call "stop" method
- delete the session object
- return an acknowledgement html page
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jan 2008
Posts: 3
Reputation:
Solved Threads: 0
Re: Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#7 Jun 4th, 2008
I've never tried to do this, but I think you're going to have to track the thread ID of the long-running process and terminate that thread when the user clicks your "stop processing" button in your app. I don't think you can detect them pressing the browser's cancel button. Also, I have never dealt with threads so I have no idea how to implement this suggestion.
Re: Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#8 Jun 4th, 2008
•
•
•
•
I've never tried to do this, but I think you're going to have to track the thread ID of the long-running process
•
•
•
•
and terminate that thread when the user clicks your "stop processing" button in your app.
•
•
•
•
I don't think you can detect them pressing the browser's cancel button.
•
•
•
•
Also, I have never dealt with threads so I have no idea how to implement this suggestion.
Aside from the fact that this thread is 2 years old.
Last edited by masijade; Jun 4th, 2008 at 1:21 pm. Reason: typos
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Re: Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#9 Jun 4th, 2008
IMO creating and manipulating threads in a managed environment is bad in itself since the request is already being processed by a thread and the chances of the programmer screwing up with threading and making the mess out of the entire affair is pretty high. Plus, there is no reliable way of completely stopping a thread since it's inherently unsafe and has been deprecated.
If the user isn't expecting a quick response, one possible way would be to use asynchronous messaging. A better method would be to make the entire process interactive and execute the process in chunks so that the user always has the option of going back or canceling the process under consideration.
If the user isn't expecting a quick response, one possible way would be to use asynchronous messaging. A better method would be to make the entire process interactive and execute the process in chunks so that the user always has the option of going back or canceling the process under consideration.
I don't accept change; I don't deserve to live.
Re: Stopping a very time consuming class method's execution on tomcat server using JSP.
0
#10 Jun 4th, 2008
As far as the programmer making a mess of the programming, that can always happen.
And, I never said he should call thread destroy, or anything in that manner. I said to call interuppt and let the Thread clean itself up (and those actions are once again something the programmer must do), which is not, of course, deprecated.
The last paragraph, of course, is another very good option, though.
I agree, that it is not a very good idea to have a browser wait on a long running process, it would be a much better idea to have a "batch" style backend that the user can either check on at a later date, or that the backend can notify the user in some way (email, sms, etc.).
Some things cannot always be run in chunks, however. As an example, I recently had to write a Monte-Carlo financial simulation that operated on a few hundred thousand transactions, over a 10 year time period on a quarterly basis, over a minimum of 20000 iterations. The simulation could not be broken down (and still be effecient) and took a couple of hours to run. We used an event driven batch-style backend that sent an email upon completion.
And, I never said he should call thread destroy, or anything in that manner. I said to call interuppt and let the Thread clean itself up (and those actions are once again something the programmer must do), which is not, of course, deprecated.
The last paragraph, of course, is another very good option, though.
I agree, that it is not a very good idea to have a browser wait on a long running process, it would be a much better idea to have a "batch" style backend that the user can either check on at a later date, or that the backend can notify the user in some way (email, sms, etc.).
Some things cannot always be run in chunks, however. As an example, I recently had to write a Monte-Carlo financial simulation that operated on a few hundred thousand transactions, over a 10 year time period on a quarterly basis, over a minimum of 20000 iterations. The simulation could not be broken down (and still be effecient) and took a couple of hours to run. We used an event driven batch-style backend that sent an email upon completion.
Last edited by masijade; Jun 4th, 2008 at 4:27 pm.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- running Perl/CGI scripts under Tomcat server (Perl)
- Tomcat Server (Java)
- difference between TOMCAT server and WEBLOGIC server (Java)
Other Threads in the JSP Forum
- Previous Thread: open separate window
- Next Thread: how to delete multiple records using jsp
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial video web






