Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the best way to run a schedule??  RSS feed

 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a xml file having schedules.. Looks like below.. usually the schedule is done for one full month at a time..

<schedule>
<job date="3/3/2007" start="05:06:07" end="06:06:07">
<job date="3/3/2007" start="05:06:07" end="06:06:07">
<job date="3/4/2007" start="07:06:07" end="08:06:07">
<job date="3/4/2007" start="09:06:07" end="10:06:07">
</schedule>

on a 'date' at the 'start' time a job starts (basically a video recording) and at 'end' the job stops.

Currently I am using a Timer,TimerTask classes to spawn off two threads for every job one to start the job and the other to end the job.

I see that for a full month schedule with say 5 jobs a day, we have 3000 threads scheduled.

While it is not a big performance hit in my case, I am wondering what the fine-tuners think about this approach, whether there is a better way of handling this. Please advise, thanks for your time...

Brian
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you schedule all your TimerTasks using the same Timer (which you probably should), then you should get only one thread (in addition to the main thread) that runs the 3000 tasks in succession, at their scheduled times. This is pretty efficient, but could get into troubles if any individual tasks take too long - they block you from running the other tasks.

If you're using JDK 5 or later, you can use something like

to create something similar to a Timer that's backed by a pool of 10 threads, so that one task can't easily block the others.

You may also want to look into quartz, especially if you're on a JDK older than 5. I don't really know how its features compare to those in JDK 5, but I've heard good things about it.
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,

Thank you for the response, my tasks are not too big so blocking is not an issue.. So I guess I should stick to what I have as of now. I have Java 5.

And yes, I am using the same Timer object to schedule tasks.. I have TimerTask subclassed innerclass in my Timer class , so is it not true that there are multiple (3000 in above case) threads that are managed by a single Timer??

Brian
[ July 10, 2007: Message edited by: Brian Percival ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, that is not true.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to run a schedule is with the facilities provided by the OS.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!