multithreading - Timer in java ,time difference problem -


I want to create a timer for my app. Sample code is shown below. When the method is called datetwo () at the same time in milliseconds there is shown in the main method. Please help me with this

  import java.util.Date; Import java.util.Timer; Public Square Timer Face {Timer Timer; Fixed date date = new date (); Fixed date date 2 = new date (); Public static zero timer method () {New thread () {Public went from zero ({{{true}} {sleep (10000); datetwo ();}} grip (interrupted predefined) {}}}. ;} Public static zero data () {System.out.println ("OK, it's time to do something!"); System.out.println ("time is" + date2 .getTime () + "19 1/2 to 1 milliseconds ");} Public Static Zero Main (String Array []) Exception {System.out.println (" Time is "+ date.getTime () +" Millesconds from 01/01/01 ") Throws; System.out.println ("In the mean time Set some time for. "); TimerMethod ();}} << Code>   

You are creating both the date s the same moment, as the stable variable above.

change date.getTime (both) better and date2.getTime () by new date (). GetTime () or System.currentTimeMillis () . It will print real time.


Comments