Solved

Timer and Threads

Posted on 2002-03-28
6
208 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert String matching to regex in java 4 33
Java string replace 11 47
sql import cannot be resolved jsp 3 23
Crystal Reports Licensing Questions 4 12
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

778 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