• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Keep running tomcat and avoid crash

 
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello;

My application is Spring MVC.
I use try catch finally block and even in my database queries I try to avoid getting null result as much as I can. But sometime and for some reason, an error is happening (due to something was not expected). The problem that tomcat 7 (which is running in CentOS) is crash and then we need to do  restart for it to be able to resume the work.
How can I avoid this? We need tomcat to keep running, so the user can resume his work while navigating other pages which does not contain any problems and of course we are monitoring the error logs and we can work to resolve the reason for the error, but we need tomcat to stay working and not crash, how to do this? What kind of configuration is needed?

Regards
Bilal
 
Saloon Keeper
Posts: 13014
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds very strange to me. Exceptions that occur while you're handling a request should never stop the application container. Something worse than a simple null pointer during your request is happening.

There is no other option than to find the cause of the problem and to fix it. There are no quick hacks.
 
Saloon Keeper
Posts: 23774
161
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 properly wrapped your database code with try/catch then Exceptions should never extend outside of the failing webapp.

Furthermore webapps are not running as processes. They behave more like DLLs, so you can't normally crash an entire webapp. just the current request. If the current request doesn't capture the failure internally like it should, the Exception would fall out to Tomcat, which would return an HTTP code 503 error.

If Tomcat itself is crashing, then you've got a serious problem in how the server is installed and configured or your webapp is so badly-designed (request handlers spawning threads and the like) that the webapp is corrupting Tomcat. Webapps that conform to JEE standards won't corrupt Tomcat.
 
Bilal Ghayad
Ranch Hand
Posts: 48
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your kindly help and reply.

Actually tomcat is stay working (up and running) but to be able to navigate my application pages, I have to restart the tomcat.
I am using try catch as much as I can, but the question is:
Let us assume there is one place we did not place try and catch, and the application faced the error, so why I have to restart the tomcat to be able to resume the work on the application? I can understand that it will display error at the page that the error occurred but if we clicked on back or if we tried to navigate any other page, it should resume the work without need to restart the tomcat.

How to resolve this problem?

Regards
Bilal
 
Stephan van Hulst
Saloon Keeper
Posts: 13014
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bilal Ghayad wrote:I am using try catch as much as I can


This sounds bad. Catching exceptions more often than you need is worse than not catching them at all.

Let us assume there is one place we did not place try and catch, and the application faced the error, so why I have to restart the tomcat to be able to resume the work on the application?


Could be any number of reasons. Maybe you caught an exception that was not meant to be caught, and it sent the application in an illegal state. This becomes especially hard to debug if you catch exceptions silently.

How to resolve this problem?l


Stop blindly catching exceptions. When an exception occurs, your application is telling you one of three things:

1) The user did something wrong. Show an error message with a clear explanation to the user. You can only do this if you understand what the user did wrong. Typically, you can handle this case without exceptions by validating the user's request.

2) You did sonething wrong. Stop plugging holes by catching exceptions. Fix the problem.

3) Something went wrong that is outside your control. Maybe a hard drive failed. Maybe lightning struck your hosting center. Catch the exception at the correct abstraction level, and deal with the exception in a way that's appropriate for that specific exception.
 
Tim Holloway
Saloon Keeper
Posts: 23774
161
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

Stephan van Hulst wrote:Maybe you caught an exception that was not meant to be caught, and it sent the application in an illegal state.



Web applications are not processes, they are request handlers. As such, the only "state" that they are allowed is Application-scope objects. There is no run state because requests run under pool threads that must be returned clean to the thread pool when the request handling is done. If they are not clean, that corrupts all of Tomcat.

I still haven't seen what exactly Tomcat or the webapp is doing when a restart is required. No, you should NOT expect good things when the user presses their "Back" button nor for that matter when they press the "Refresh" button. While the application shouldn't have state, the user session definitely can, and when you go outside the normal workflow, it can be a problem. That's why so many web stores say "Do not click Submit more than once."

But that would damage only the current user's session, not any other user's session nor the Tomcat server itself. They should proceed to run as normal.

So again, I need to know precisely what doesn't work. Only then can I suggest a solution.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic