How to run a task every month using Java

Asked

Viewed 108 times

-2

Hello,

I would like to know how I can schedule a task to be executed all 1 day of the month.

Thank you.

  • 4

    Show us what you have already tried by posting your code. You can edit the question and add your code to it and format it too using the option {}. Make a tour to learn about the site.

  • Does it necessarily have to be in Java? A simple script in bat or bash would solve your problem.

1 answer

-3


LocalDate date = LocalDate.now();
boolean isFirstDay = date.getDayOfMonth() == 1;
if (isFirstDay) executaTarefa();

But I advise to do this by operating system, on Windows has the task scheduler and on linux we have the crontab. Both are easy to use.

  • More if I use the"Windows Task Scheduler, I will be able to run a code inside my . jar? And this code you sent, for me to check with it I can use a Timer(), Checking every 10 minutes? Thanks.

  • 1

    @Skyvox won’t not. the scheduler works the part inside windows. This answer does not answer what was asked, because your question is too wide.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.