Auto launch ejb.Timer without webapp?

I

iksrazal

Hi all,

I'd like to perform a DB task every hour or so in an EJB container.
However, I can't seem to figure out a simple way to have the timer load
on startup as I can't do a simple load-on-startup servlet or
ServletContextlistener. The app is contained only in a jar, deployed in
JBoss that just has web services exposed as Stateful Beans.

My idea is to do it via a static initializer, but I'm wondering if
there is a better way?

Any ideas?
iksrazal
 
J

jan V

My idea is to do it via a static initializer, but I'm wondering if there
is a better way?

Static initializers are tempting, aren't they? But they're real nasty when
it comes to unit testing objects of such classes... the static initializer
can get in the way, as it will (obviously) execute whether you want it or
not. I would advise against using static initializers that depend on
connecting or talking to the outside world, or spawn threads. Make such
initializers into static *methods* instead, so the class can be loaded
without such potentially show-stopping side-effects.
 
I

iksrazal

jan V escreveu:
Make such
initializers into static *methods* instead, so the class can be loaded
without such potentially show-stopping side-effects.

Good point. How would I then call/not call the static method on
startup?

Thanks for the reply,
iksrazal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top