paramupk
paramupk

Reputation: 626

Scheduling a Job in webserver -Java

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

Answers (4)

Arul Dhesiaseelan
Arul Dhesiaseelan

Reputation: 2009

You could use Flux to schedule your java jobs inside a web container.

Upvotes: 0

RajeshS
RajeshS

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

Tomasz Blachowicz
Tomasz Blachowicz

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

EricParis16
EricParis16

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

Related Questions