Solved

Timer and Threads

Posted on 2002-03-28
6
188 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
Comment Utility
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_
Comment Utility
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
Comment Utility
Thanks for ur help. but i not sure which method is working. i hope there are more answers.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 16

Expert Comment

by:heyhey_
Comment Utility
IMHO TimerTask will always execute all the jobs.

did you tried some simpletest ?

0
 

Author Comment

by:chencc77
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

771 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

10 Experts available now in Live!

Get 1:1 Help Now