How to use TimerTask in java
Most people do not understand the knowledge points of this article "how to use TimerTask in java", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use TimerTask in java" article.
1. JDK1.3 introduces TimerTask tools into Java language. This tool allows you to perform tasks on a regular or delayed basis.
2. The implementation of Timer is very simple, creating a timer thread and building a queue waiting for events according to the execution time.
The TimerTask thread is a daemon thread, so it does not prevent the program from exiting. Because timing events are executed in the Timer thread, you must ensure the correct synchronization of any data items used in tasks in the Timer thread.
Example
Public static void main (String [] args) {Timer timer = new Timer (); final CalculatePrimes calculator = new CalculatePrimes (); calculator.start (); timer.schedule (new TimerTask () {public void run () {calculator.finished = true) }, TEN_SECONDS);} above is the content of this article on "how to use TimerTask in java". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.