Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
My applcations need to run a particular methods for a period of time like 3 seconds or 5 seconds interval, according to the configuration in the file
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Mani
Quaerendo Invenietis
Originally posted by Mani Ram:
I would prefer Timer / TimerTask over Threads for this scenario.
From Java Practices.com:
if it is to be done later, or periodically, use Timer and TimerTask it it may take a long time, or may block, use a Thread
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Originally posted by Mani Ram:
it it may take a long time, or may block, use a Thread
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Originally posted by Ko Ko Naing:
Thanks a lot for the link, Mani... But I'm not qutie clear with the above sentence... Shouldn't it be if it take a short time, we should use a Thread? because as far as I know, if we let a Thread to be blocked a long time, it would not be good...
Could you explain a bit details for this issue? Thanks...
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.
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.
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
The biggest strength of Timer is if you have many different tasks to schedule at different times. Timer takes on the job of scheduling everything using a single thread, very efficiently. If you do this yourself it's probably easiest to use a separate thread for each task - but this can be unnecessarily inefficient if you've got a lot of different tasks to schedule. Timer makes this a lot easier to handle efficiently.
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Originally posted by Pradeep Bhat:
Deprectaion of threadsWhy?
![]()
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Originally posted by Pradeep Bhat:
Ko ko,
You may also have a look @ Quartz
http://www.onjava.com/lpt/a/4637
Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |