gabac
gabac

Reputation: 2078

Shedule tasks question

I have a though question :)

Let's say you get some data which is due at a certain point int the future. You get A saying my task is due in 1h and other which says his task is due in 1.5h. The information is collected on your server. In which programming language or even how would solve that? So task a will be executed in 1h, task B in 1.5h. I read something about java scheduler but I'm not yet sure if this is the right way.

What are ur ideas?

Cheers

Upvotes: 1

Views: 200

Answers (4)

9000
9000

Reputation: 40894

If, for some reason, you decide to implement such a system yourself, here's the idea.

  • Have a list where you keep your tasks, ordered by due time.
  • Create a daemon process that sleeps most of the time, and wakes e.g. every minute, or even irregularly using sleep(). When the daemon wake up, it takes tasks from the queue; if task's due time has come, it runs this task in a separate process (or thread), and removes it from the queue. Having started all due tasks, it goes back to sleep.
  • Devise an interface to add new tasks to the queue.

Upvotes: 1

time4tea
time4tea

Reputation: 2197

If this is a long running process, then you can use a ScheduledExecutorService in java to achieve this. Clearly, though if your process exits, then the task will be lost.

cron or quartz would also work as more persistent schedulers. each has their own wrinkles though.

Upvotes: 1

CoolBeans
CoolBeans

Reputation: 20800

If you are looking for programmatic access then take a look at Quartz - a java scheduler. They also have a good tutorial resource.

Upvotes: 1

Sam Dufel
Sam Dufel

Reputation: 17598

cron is installed on most unix web servers - you can use it to assign tasks to execute later.

Upvotes: 1

Related Questions