0

I want schedule a task in Restful web service (Java,Maven). I tried to use cron job or any Scheduling class for restful web service, but I couldn't config, I want to send a request next month 21st day at 18:30, How do I do it using java? What technology I want to use?

I tried lot of other ways. Sometimes my web service doesn't work correctly. Why does this happen? Is this scheduling class include inside thread class? How do I solve it?

Abishek
  • 9,788
  • 17
  • 65
  • 106
Thilina Sampath
  • 2,860
  • 5
  • 32
  • 59

1 Answers1

2

In a JavaEE environment (which I guess is desired as indicated by your tag) you could easily accomplish this by using the Timer Service. I think what you want to accomplish is to call a Web Service at a timely fashion.

In this case you basically have to create a schedule,

 @Schedules ({
      @Schedule(dayOfMonth="21"),
      @Schedule(hour="23",minute="30")
 })

You also need a caller method,

 @Timeout
 public void timeout(Timer timer) {
    System.out.println("Calling the Service");
    //Here call your service.
 }

If you want to call the service in order to create a web service call in the future you can still use an EJB and the timer service to dynamically create a timer based on the input parameters passed by the Web Service. The EJB will then make the call as indicated by the dynamic timer.

You can also check the tutorial. http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html

PutzKipa
  • 5,885
  • 3
  • 21
  • 30
Spyros K
  • 1,940
  • 1
  • 19
  • 30