I want get the start and end time ,date from user and start the processor from user starts the time and date and ends upto the end time and date.How can i use this in TimerTask.
Asked
Active
Viewed 102 times
2 Answers
2
I would stay away from Timers and TimerTasks and rather use Executors.newScheduledThreadPool
Refer https://stackoverflow.com/a/409993/628943
If you are looking for higher level apis you can use Quartz or if you are on Spring you can use the @Scheduled
annotation .

Community
- 1
- 1

Ajay George
- 11,759
- 1
- 40
- 48
0
The main thread can simply sleep until the start time.
After that have the main thread launch a TimerTask scheduled to activate at the end time, and start doing its job. Checking every loop whether its Thread is interrupted.
The TimerTask's job is to interrupt the main thread.
So when the TimerTask activates, it interrupts the main thread. The main thread will exit its job execution loop since its thread is interrupted.

bowmore
- 10,842
- 1
- 35
- 43