Guest User

Untitled

a guest
Jan 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. public class RandomThread extends  Thread{
  2.  
  3.     static AtomicReference<Double> result = new AtomicReference<Double>(3.0);//test with 2, 0, -1, 58 : it's fun
  4.  
  5.     @Override
  6.     public void run() {
  7.        
  8.         try {
  9.             sleep((long)Math.random()*100);
  10.             Double cacheResult = result.get();
  11.             result.compareAndSet(cacheResult, cacheResult+Math.sin(cacheResult.doubleValue()));
  12.         } catch (InterruptedException e) {
  13.             e.printStackTrace();
  14.         }
  15.     }
Add Comment
Please, Sign In to add comment