This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Periodically task performing thread  RSS feed

 
Shane Ray
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Status: Thread Newbie

What will be the most efficient way to achieve the following requirement:

-->I have a thread that needs to periodically (period set by user which could run into minutes or hours or maybe even day/s) perform some tasks. Some options that I thought of were:

1. putting this thread to sleep, or
2. having another thread (say a timer thread) send an interrupt to this thread perhaps

The basic performance objective here is to minimize system resource usage.

Thnx for any help.

Shane
 
Torsten Schindler
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My status: Thread newbie

I not sure but maybe the Quartz system would be a solution:
http://www.opensymphony.com/quartz/

If the status of the object with your run()/execute()-method should be
saved in the objects fields between the executions,
Quartz will not be very helpful, because it creates a new object
for each triggering event.

Best,

Torsten
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My goodness. Talk about killing a gopher with a chaingun.

The class "java.util.Timer" should serve your needs nicely. You package your task as an class that implements Runnable, create a Timer, set the timer, and it takes care of firing the Runnable after specified delay.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like the use the OS job services in cases like this.
 
Magnus Palm�r
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Quartz or not is a chaingun depends upon what need to be done.
If it is simply a matter of delaying a one shot work a timer may be enought.

I found Quartz fairly simple to use and it is really good if you want to set up crontab like scheduling (using a quartz CronTrigger).
(I.e. do this work every 15min between 7 am and 5pm Monday to Friday.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!