Topic 1: write an application using Java multi-threading mechanism to achieve synchronization output time display.
1.date1.java
. 1 Package multithreaded; 2 . 3 Import java.util.Date; . 4 . 5 class date1 the implements the Runnable { . 6 . 7 public void run () { // override the run method . 8 the while ( to true ) { // cycle of the output time . 9 a Date DATE = new new a Date (); // get the current time 10 System.out.println (DATE); . 11 the try { 12 is the Thread.sleep (1000); // set the thread sleep time lS 13 is } catch (InterruptedException e) { 14 // TODO Auto-generated catch block 15 e.printStackTrace(); 16 } 17 } 18 } 19 20 }
2.Test.java
. 1 Package multithreaded; 2 . 3 public class the Test { . 4 . 5 public static void main (String [] args) { . 6 date1 = DATE_1 new new date1 (); // Create a thread object . 7 date_1.run (); // thread into the run state . 8 . 9 } 10 . 11 }
3. Run results