Auto start EJB when Sun Application Server start

Is there a way to make an Enterprise JavaBean auto start when the Sun Application Server starts?Thanks,janir
[129 byte] By [janir4a] at [2007-11-15]
# 1

What type of bean, and why would you need to do that?

A relatively cross-server easy way would be to use a <load-on-startup> servlet (in the Web.xml ) which would call the bean in its init() method.

I'm not a Sun Server user, so there maybe a server-specific way to do that, that I'm not aware of.

karma-9a at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Well; to describe more in detail: I'm building a integration server; where i build a Web portal, and have connected several EJB's that does the work of the different interfaces. (These are JMS connected beans)

What i need to build now is an application controlling the work queue/scheduling. For this purpose i need an application that auto starts with the application server, and checks for "new" work by example once a minute.

Regards,

janir

janir4a at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 3

You could do that at the Web layer, and implement a ServletContextListener.

The class will then listen for application stratup and shutdown events, and the contextInitialized() method in particular will call your bean.

You'd of course mention the listener in your web.xml under <listener>.

karma-9a at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 4
I'm probably a bit slow here; but would greatly appreciate some more details about this solution.Regards,janir
janir4a at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 5
[url= http://www.java-tips.org/java-ee-tips/java-servlet/how-to-work-with-servletcontextlistener.html] How to work with ServletContextListener[/url]
karma-9a at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 6
I'm not quite sure if this will do the trick; i need this timer to work in the background no matter the state of the web application.Regards,janir
janir4a at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 7

Hi janir,

What karma-9 is suggesting is simply using the web container initialization event to call into an

EJB that will then create a periodic EJB timer.Unfortunately, there are no container-initialization

or automatic deployment initialization events in EJB, so the best you can do, portably, is to leverage

the web container events by packaging a simple .war along with the ejb-jar into an .ear.All the

servlet context listener needs to do is lookup (or inject) a reference to a stateless session bean that

defines a business method in which the EJB timer is created.Note that you should also check to

see if the timer has already been created before creating it since the EJB timers are persistent and

the web container initialization event happens every time the server is started.

We are planning to add better support for this use-case in the next version of the EJB spec.

--ken

ksaksa at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...
# 8
OK, I see! ( Now i know why i got so few hits on "autostart ejb" on Google..... )ll try this on Monday.Thanks karma-9 and ken!janir
janir4a at 2007-7-12 > top of java,Enterprise & Remote Computing,Enterprise Technologies...