I am new in Thread and I never use a thread now i want that my same code will be automatically executed after every 15 second now how can i use thread in it...please give me example...... or any other way same code executed after some time...........
Thanks for your valuable comments. Actually my post was based on explaining the idea of the periodic thread running in a very simple view to allow for understanding the concept without using a thread part. The second point I want to stress on is the usage of java.util.Timer; the Timer has a draw back which is there is only one thread that execute the TimerTask hence if the timer task takes too long to run, the timing accuracy of other Timer Tasks can suffer; for example, if the recurring TimerTask is scheduled to execute every 20 ms and another TimerTask takes 40 ms to run, hence, the recurring tasks get called twice which will will have different consequences.
You say you just want some piece of code executed regularly (periodically) ?
Why use threads at all ?
Use job scheduling instead . A possible elegant solution is the open source Java job scheduler Quartz. It abstracts you from threads entirely.
What's the point of making things complex when they could be simple...
SCJP 6 (86% - the hard way), SCBCD 5 (81% - the hard way)