Restart Tomcat from JSP
Hi,
I have the following requirement. I need to restart the server after I do some report generation.
If I click some button on my web page. It should shutdown the server and restart it.
I can stop the server by coding <% System.exit(1) %>. But after I close I need to restart it. Can we execute batch script to execute shutdown.bat and startup.bat of tomcat in that sequence to do this?
Thanks
[429 byte] By [
j_thomasa] at [2007-11-27 11:40:33]

When you shutdown the server, that's it. Code running in the server can't then start it up again. Because it's not running any more.
Why do you think you need to do this "after some report generation" anyway?
If it's tomcat, tomcat has it's own admin port. Use that to stop and restart your application, if you feel this is truely needed. Restarting the app server is definately not needed, and restarting your app should not be needed, but, in either case, it should not be done from one of the applications, use Tomcats admin portal.
Actually after generating the report the tomcat server becomes too slow. So we have to manually restart it. I am thinking of some way to automate it.
> Actually after generating the report the tomcat
> server becomes too slow. So we have to manually
> restart it. I am thinking of some way to automate it.
Fix the problem, don't work around it! It's something wrong with your application
One possiblitly is that you are caching too many things, either in application or session context, or possibly even only as instance variables. Write a method to clear these things, and your problem may go away. It could also have to do with simply accessing a bunch of resources to generate the report and never releasing those resources.
In any case, the problem is probably not Tomcat, but (and I don't mean to offend, but it is the way it is) sloppy or innefficient coding on the part of the application.
I am a mainframe personnel working on CR in a Java application. (Not much depth in java plus no idea who coded this application)
The application actually retreives data from MS Access to create the report. The queries are extensive and lot of queries are executed inside some outer query. Finally the output is written into and excel.
I have observed that each time the server generates the report, the report generation becomes slow. It takes 4s intially, then 5s, then 10s, then 30s and so on.
I tried coding the array list (used to store the query results to create excel) to null. Doesn't work.
Tried even System.gc().
How can I know that too many things are "caching"?
You need to get a Java Programmer to look at it. I will say, that if you are using the JDBC-ODBC that comes with the JRE to interact with the MSAccess and MSExcel, then every time that it runs correctly you have gotten lucky, because that bridge is not thread-safe and JSP are inherently threaded (the tomcat initiates it once, then spins off threads of that same instance to handle requests).
sounds like you're letting memory clutter up with unused object references.
Garbage collection won't pick them up because there are still references to it.
Manually trying to force garbage collection is another Very Bad Thing (tm), almost as bad as restarting the server to hide the fact that you have a shoddy application running on it.
Almost certainly you're storing something (probably the entire data for the report) in some global variable which you then forget about but don't actually let go out of scope.
Another near certainty are database connections and other database resources being opened but never closed.
Both are extremely common mistakes made by inexperienced programmers.
Your proposed "solution" is so wrong in every way.
Have somebody profile that app to see what's really going on and stop guessing.
%
As Jwenting pointed out .....check the resources if properly closed.
Check for SQL and I/O resources.If not apply proper try catch and close the resources in the finally block.
These are indeed very common problems overlooked and
that cause huge performance impacts.
I dont think shutting down the server or system.gc() is a solution.
Dig into the code and find out if the resources are closed.
Do check your session((if any) management also.
Thanks all for your responses.
I wrote a batch script and scheduled to restart the server every night. This is a temporary fix.
Will ask some Java personnel to look into it. I have observed that if i comment out the part of code which actually writes the excel (we are using some jxl.* package to format excel), the performance is improved greatly.
i.e., only if I write the array list to excel, things are getting slowed down. The max size of the report generated is 1 MB.
Any pointer in this regards?
yes, the problem is most likely with that library.
If it's your own, fix it.
If not, contact the authors to have it fixed and/or investigate alternatives.