Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to load a class on app server startup

 
shashiD kanth
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a java class, not servlet. I want to load this class as soon as servlet container starts. In that java class I have written some code in static block, which is executed as soon as class is loaded into JVM.
Thanks,
Shashi.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could just implement a ServletContextListener that calls your class in its contextInitialized method.
 
shashiD kanth
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give some example code on this. Your help is appreciated.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Create a class implementing javax.serlvet.ServletContextListener
2. Implement both contextDestroyed and contextInitialized
3. Instanciate your class in contextInitialized
4. Declare the listener in web.xml using the <listener> tag
 
shashiD kanth
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!! it worked for me
 
subbarao N.V
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

Suppose your class is student,you create a subdirectory as part of bea directory in the weblogic and place the student.class.Before starting your weblogic set the class path to student.class and start the server.


This is the one way


It is performance wise good.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just make sure you NEED that class loaded at startup.

Lazy Loading should be the rule, not the exception. I once workd on a massive piece of iron that took 30 minutes to boot, just because the developers decided every EJB had to be in memory before the application should handle any client requests.

Lazy Loading Rocks. Everyone, BE LAZY!!!
[ August 27, 2006: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic