ferrybig

windows time accuracy using System.timeMilies

Feb 4th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.stream.LongStream;
  2.  
  3. /**
  4.  *
  5.  * @author Ferrybig
  6.  */
  7. public class TimeMilies {
  8.    
  9.     public final static boolean USE_SLEEPING_THREAD = true;
  10.     public final static boolean USE_DISTINCT = true;
  11.    
  12.     public static void main(String... args) {
  13.         if (USE_SLEEPING_THREAD) {
  14.             Thread t = new Thread(() -> {
  15.                 try {
  16.                     Thread.sleep(Long.MAX_VALUE);
  17.                 } catch (InterruptedException ex) {
  18.                     Thread.currentThread().interrupt();
  19.                 }
  20.             });
  21.             t.setDaemon(true);
  22.             t.start();
  23.         }
  24.         LongStream s = LongStream.generate(System::currentTimeMillis);
  25.         if (USE_DISTINCT) {
  26.             s = s.distinct();
  27.         }
  28.         s.limit(50).forEach(System.out::println);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment