Solved

Timer and Threads

Posted on 2002-03-28
6
199 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JAVA part two 5 57
simple java question 3 44
maven project error 5 48
MySqlDump not dumping triggers 1 15
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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 …

919 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now