File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Websphere and the fly likes Startup Classloading in Websphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Startup Classloading in Websphere" Watch "Startup Classloading in Websphere" New topic

Startup Classloading in Websphere

Sumona Dev

Joined: Oct 17, 2002
Posts: 4
I am using WebSphere4.0 AEs.I want to load a class as soon as server starts up. In there any option for that.
For example in weblogic server admin console there is one option called startup and shutdown.
There you can specify the class which you want to load.Is there any option in WebSphere?
Help needed.
Rajeev Gupta

Joined: Oct 21, 2002
Posts: 7
You can pre load a servlet, and let it perform the tasks at startup time. This can be setup in web.xml file.
<your servlet parameters ... />

Rajeev Gupta<br />SCJP,SCJD
Rajeev Gupta

Joined: Oct 21, 2002
Posts: 7
<your servlet parameters ... />
<load-on-startup>1</load-on-startup> </servlet>
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
What do you mean by
.I want to load a class as soon as server starts up.

Do you mean as soon as the Admin server starts.
Or as soon as the application server where your application is deployed starts
What kind of class is it ? How are you going to use it ?
Maybe this documentationm from the infocenter could help

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
Junaid Bhatra
Ranch Hand

Joined: Jun 27, 2000
Posts: 213
WebSphere has a similar feature, called as Custom Services. But unlike WebLogic, in which you can give any arbitrary class file with a main() method, the custom service in WebSphere *has* to implement a specific interface. When the application server starts up, it will call a particular method on your class. Search the WebSphere docs for specifics on this.
However you must be careful in using this WebSphere feature. WebSphere makes no guarantee about the order in which this custom service will be called. Also there is no guarantee that any app-server services (eg, JNDI naming service, Connection Pools) will be fully initialized when your custom service is called. So if your custom class needs to lookup, say a JNDI reference, it may not be available!
As someone else suggested, the cleanest way is to implement a startup servlet, which simply calls your custom class within the init() method. Using this approach, it is guaranteed that the app-server services will be fully initialized by the time the servlet is loaded.
I agree. Here's the link:
subject: Startup Classloading in Websphere
It's not a secret anymore!