Forums Register Login

How to run a task every month using Java

+Pie Number of slices to send: Send
Hello,

I would to know how can I schedule a task to be executed every month, I was trying with a method I see on StackOverflow: "http://stackoverflow.com/questions/4107011/java-monthly-timer".
Thank You.
2
+Pie Number of slices to send: Send
my advice: don't.

Java is not really the best tool for this sort of thing. On *nix systems, you'd use cron. on Windows, you'd use a scheduled task.

As my old boss used to say, "Use the right tool for the right job".
+Pie Number of slices to send: Send
 

fred rosenberger wrote:my advice: don't.

Java is not really the best tool for this sort of thing. On *nix systems, you'd use cron. on Windows, you'd use a scheduled task.

As my old boss used to say, "Use the right tool for the right job".



But how can I do it on Windows?
1
+Pie Number of slices to send: Send
 

Dennis Colossal wrote:
But how can I do it on Windows?



If you are using server side Windows, you can you the "at" command. If not, you can either contact Microsoft to see if it is available, or load something like Cygwin to get Unix services like cron... or you can use a schedule task (ie. schtasks) as fred mentioned, which I have never done, so can't help...

Henry
+Pie Number of slices to send: Send
But btw, have no way to do it with Java? It have no support class to make it?
Thanks.
2
+Pie Number of slices to send: Send
 

Dennis Colossal wrote:But btw, have no way to do it with Java? It have no support class to make it?



Sure.... Java can do this via a scheduled executor, but is it guaranteed to be running? What happens when the machine gets rebooted?

With OS services, those tasks will be running at the requested day and time, as long as the OS is running. The OS will deal with restarts, etc.... Remember that you are talking about months in terms of time frames. Is Java really the preferred option?

Henry
+Pie Number of slices to send: Send
 

Henry Wong wrote:

Dennis Colossal wrote:But btw, have no way to do it with Java? It have no support class to make it?



Sure.... Java can do this via a scheduled executor, but is it guaranteed to be running? What happens when the machine gets rebooted?

With OS services, those tasks will be running at the requested day and time, as long as the OS is running. The OS will deal with restarts, etc.... Remember that you are talking about months in terms of time frames. Is Java really the preferred option?

Henry




But, I need execute a method on my Java plugin, So isn't better I make an method on my Java plugin?
+Pie Number of slices to send: Send
 

Dennis Colossal wrote:But btw, have no way to do it with Java? It have no support class to make it?


Java is a programming language. Using java, you can write programs to do any task. A program has to be 'executed'. It can be killed by a user or by the operating system. If a program is no longer running, it simply cannot do your task.

As suggested by others, there are daemons/services which are provided by the operating systems to do repeating tasks. These are special programs which run in the background. Usually, an operating system manages  it and ensures that it's always running even after rebooting.
+Pie Number of slices to send: Send
 

salvin francis wrote:

Dennis Colossal wrote:But btw, have no way to do it with Java? It have no support class to make it?


Java is a programming language. Using java, you can write programs to do any task. A program has to be 'executed'. It can be killed by a user or by the operating system. If a program is no longer running, it simply cannot do your task.

As suggested by others, there are daemons/services which are provided by the operating systems to do repeating tasks. These are special programs which run in the background. Usually, an operating system manages  it and ensures that it's always running even after rebooting.




But look at this class: "http://stackoverflow.com/questions/4107011/java-monthly-timer" You put on main class, and it will always when the plugin start will remove the last timer, and create a new timer. But It doesn't wotk to me I don't know why.
+Pie Number of slices to send: Send
While the SO link has suggested many ways, the discussion here was about feasibility rather than possibility.
Where are you going to run your program ?
What is the error you are facing ? ItDoesntWorkIsUseless
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
 

salvin francis wrote:While the SO link has suggested many ways, the discussion here was about feasibility rather than possibility.
Where are you going to run your program ?
What is the error you are facing ? ItDoesntWorkIsUseless



I want to execute a Method, Let's say this method is a message so every first day of moth I want to send a message.

I change this class to it:


But it don't show nothing.
+Pie Number of slices to send: Send
For that to work, the program must be running all the time, waiting until it's time to display the message. You can't just run the program once, let it end, maybe switch off the computer and switch it back on tomorrow, and still expect the timer to go off. It can only go off as long as the program is running. You could use this when you have a program that is running 24x7 on a server. But for a normal desktop or laptop, where you are not running your program all the time, this isn't a great way to do it.

That's why it is better to use the operating system's task scheduling mechanism to do this. The operating system is always running as long as the computer is switched on, and most operating systems have ways to schedule running a particular program at a specific time. The only thing you would have to do is write a program that displays a message, and then you use the operating system's facility to run that program at the time you want the message to be displayed.
+Pie Number of slices to send: Send
So, I can implements: Quartz Scheduler on my code? This is better than my Class method?
and POOF! You're gone! But look, this tiny ad is still here:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4129 times.
Similar Threads
questions java.util.Timer
eternal process
Invocation of a TimerService
Timer Schedule
Thread-based timer versus Timer Class-based timer
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:49:06.