aspose file tools*
The moose likes Servlets and the fly likes Startup servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Startup servlets" Watch "Startup servlets" New topic
Author

Startup servlets

Prad Rayan
Greenhorn

Joined: Nov 18, 2001
Posts: 7
Hi ,
In conversation with an ApplicationServer administrator , I came across the fact , that servlets should not be marked as a startup servlet (a servlet whose init() method is invoked by the application server when it comes up).The reason being , that an improperly written (read as poor exception handling) servlet might cause the servlet engine to crash .. Is this true ??
Is there an alternative to this ? Property files , I gather can be read by resource bundles , how about the Java objects which have to shared across servlets and JSP , runnning in that virtual machine ? For example , I initialize a database connection pool in my startup servlet and write the reference of that in to the contetx,so that the other entities would have access to that . In the absence of a startup servlet , how should I go about implementing it ?
Could some one provide a solution for this from the architectural perspective ?
Regards
Rayan
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Short of calling some poorly-coded JNI methods in your init() method, that's sheer horse hockey. There is no way that this could happen. Your system administrator is either repeating things he's heard (without substantiation) or making this up...
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

I suppose someone COULD have created an appserver that was that feeble, but if I found mine doing that, I'd quickly be looking for a new appserver. First of all, if a servlet was going to crash the appserver, whether it was called on startup or later isn't going to matter much -- any I'd rather have it die while people are still paying attention (at the startup console).
Secondly, you'd be losing valuable functionality. A startup servlet is an ideal place to put stuff that is required by the app on a global basis, such as initializing database and pooling subsystems.
This assertion sounds to me like some wisdom carried over from something like IIS, where compiled code is invoked directly from the main thread of the appserver and exception handling isn't a major product feature.


Customer surveys are for companies who didn't pay proper attention to begin with.
Prad Rayan
Greenhorn

Joined: Nov 18, 2001
Posts: 7
Thanks a lot for your reply . I did discuss this others , and we would be going the "Startup servlets" way . Thanks again
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
How does one mark a servlet as a "startup" servlet? I'd heard that WebLogic could do this, but is there a cross-platform way to do this on any J2EE app server (servlet container)? Forgive my ignorance, I'm still learning... Thanks!


CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)
Author of Posts in the Saloon
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
It's in the spec, any 2.2 compliant servlet container should be able to do it. Include < load-on-startup >order< /load-on-startup > as (I think) the last tag within the < servlet > tag in WEB-INF/web.xml. The order is a number that determines, well, the order in which the servlets will be started. Use a different number for each servlet, some application servers don't like it if different servlets get the same number.
[ Almost. The last tag inside < servlet > except for the < security-role-ref > tags. ]
- Peter
[This message has been edited by Peter den Haan (edited November 23, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Startup servlets