Reputation: 626
I want to schedule a job in Jboss and websphere server. I have a piece of code in java which should execute at a certain frequency independantly.And it should execute in a server continiously. Is it possible to execute a code when server starts.
Upvotes: 2
Views: 1851
Reputation: 2009
You could use Flux to schedule your java jobs inside a web container.
Upvotes: 0
Reputation: 170
Use Quartz Scheduler
as mentioned by @Tomasz Blachowicz
. Use Databse approach to configure Jobs and triggers. And just add below three line in your Startup servlet. That's It!
StdSchedulerFactory factory = new StdSchedulerFactory(configFile);
// where configFile => quartz.properties file complete path.
Scheduler scheduler = factory.getScheduler();
scheduler.start();
Hope this will work for you. I am using this and its very easy to configure.
Upvotes: 1
Reputation: 5843
I'd recommend to use Quartz Scheduler if you require full portability of the code (WebSphere, JBoss, Tomcat, etc.)
You can initialize Quartz very easily by using build-in QuartzInitializerServlet or even better QuartzInitializerListener.
Upvotes: 1
Reputation: 809
you could use Timer api.
add @Startup on your bean.
or add this to your web.xml (change properties for your convenience)
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>example.web.Servlet2Stateless</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
Upvotes: 1