0

I am using J2EE with Jboss server. I am trying to finding a way to invoke sendEmail api in my code every month.

@GET
@Path("/sendEmail")
@Transactional
public String test(){

I want to invoke this test api which can be accessed using web-browser http://localhost:8181/api/calc/sendEmail

I found some ways to do this: https://cloud.google.com/appengine/docs/java/config/cron https://www.mkyong.com/java/how-to-run-a-task-periodically-in-java/

Using cron job looks intuitive way to do this but I find it difficult to search resources to find a way to schedule invoking of the APIs using it.

Please point me to some resources where I can find a way to do so by just adding single dependency for this purpose in pom.xml

Bharthan
  • 1,458
  • 2
  • 17
  • 29

2 Answers2

1

You can use Spring Framework for this.

Something like this:

@Scheduled(cron = "0 0 12 1 1/1 ? *")
public void doScheduledWork() {

Check the following link: Spring cron expression for every day 1:01:am

Community
  • 1
  • 1
pringi
  • 3,987
  • 5
  • 35
  • 45
0

When the application is deployed in multiple boxes or multiple pods(in case of kubernetes) then in each pods the cron expression gets set.

This results in the cron getting triggered n(number of pods) times which results in error case. Better option is to call the cron from external monolith configuration systems by calling through an api.

Applying on a method with the annotation is apt if application runs in only one box(pure monolith).

mgp
  • 1
  • 2