How to stop a Runnable scheduled for repeated execution after a certain number of executions

You can use the cancel() method on Future. From the javadocs of scheduleAtFixedRate Otherwise, the task will only terminate via cancellation or termination of the executor Here is some example code that wraps a Runnable in another that tracks the number of times the original was run, and cancels after running N times. public void … Read more

java timer task schedule

This works. The key is to have the task itself (after it completes) schedule the next occurrence of the task. import java.util.Timer; import java.util.TimerTask; public class TaskManager { private Timer timer = new Timer(); public static void main(String[] args) { TaskManager manager = new TaskManager(); manager.startTask(); } public void startTask() { timer.schedule(new PeriodicTask(), 0); } … Read more

Difference between AlarmManager and ScheduledExecutorService

ScheduledExecutorService runs in your application process. If application process dies, none of the scheduled tasks will run. Hence the need for Service (so your process lives beyond Activities active part of lifecycle). While AlarmManager is critical system service that runs all the time. And if your application scheduled something and was killed, then AlarmManager may … Read more

Using the GWT Scheduler

JavaScript (in a browser) is single threaded. The event loop model means, we’re always in exactly one of two states: in the event loop executing an event handler There are many kinds of events: Click events, onload events, XHR events, timer events, … You’ll have to declare some handlers (at least one during page load), … Read more

Does linux schedule a process or a thread?

The Linux scheduler (on recent Linux kernels, e.g. 3.0 at least) is scheduling schedulable tasks or simply tasks. A task may be : a single-threaded process (e.g. created by fork without any thread library) any thread inside a multi-threaded process (including its main thread), in particular Posix threads (pthreads) kernel tasks, which are started internally … Read more

Recommended method for loading a URL via a scheduled task on Windows

As pointed out by Remus Rusanu, PowerShell would be the way to go. Here’s a simple one-liner that you can use to create a scheduled task, without needing to write a separate .ps1 file: powershell -ExecutionPolicy Bypass -Command Invoke-WebRequest ‘http://localhost/cron.aspx’ -UseBasicParsing Note that line breaks are added only for clarity in all of these command … Read more