?
Solved

Timer and Threads

Posted on 2002-03-28
6
Medium Priority
?
228 Views
Last Modified: 2010-03-31
I create a database to store date for jobs to be executed. I use Timer.schedule(TimerTask task, Date time) to do the scheduling. TimerTask will invoke a thread to run certain code. The program will the check the current date that match with date in database. If exist, it will run the TimerTask.
If i have 1000 of jobs would be run at 10.00 AM and 1000 of jobs would be run at 10.01AM. During the checking process and current time is 10.00 AM. If the checking process for 1000 jobs at 10.00 AM take more than 1 minute. how do i make sure that jobs at 10.01 AM will be executed.
I hope my question is clear to you. Thanks.
0
Comment
Question by:chencc77
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6904666
In my appinion - you have two ways to do this:
1. When get the jobs from the database - select all jobs not only for (for example) 10:05, but all jobs that must be started since the last operation. If your last operation was at 10:00, at 10:05 you will execute all jobs for 10:01, 10:02, 10:03, 10:04 and 10:05.

2. Make sure that the jobs are started by separate thread - not the thread that checks the database. This way you will minimize the time of this thread.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6907145
1. TimerTask should handle this 'problem' itself ?

2. from the docs.

> . Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.
0
 

Author Comment

by:chencc77
ID: 6909727
Thanks for ur help. but i not sure which method is working. i hope there are more answers.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:heyhey_
ID: 6909861
IMHO TimerTask will always execute all the jobs.

did you tried some simpletest ?

0
 

Author Comment

by:chencc77
ID: 6909915
did i need to create new Timer for each Job? if i have 1000 of jobs, so i will have 1000 of Timer, izit correct way to create schedules?
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 150 total points
ID: 6909927
sorry for the typo.

try creating one Timer and schedule severel (dymmy) TimerTasks for execution ... IMO Timer will call all tasks, no matter how long they executed.

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question