Advertisement
wreed12345

2 be atomic or 2 not be atomic

Mar 2nd, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. //class Derp would be initiated in another class and on a sperate thread and getTime()
  2. //would be periodically accesed to reset the time value back to 0
  3. public class Derp{
  4.     private AtomicLong time = new AtomicLong(0);
  5.    
  6.     //somewhere here time is modified
  7.    
  8.     public AtomicLong getTime(){
  9.         return time;
  10.     }
  11. }
  12.  
  13. //Could I use the following to bypass the need for the atomic part
  14. public class Derp {
  15.     private long time = 0;
  16.    
  17.     //somewhere here time is modified
  18.    
  19.     public void resetTime() {
  20.         time - 0;
  21.     }
  22. }
  23. //only resetTime would be called the exact value of time would never be needed
  24. //Since the Derp class would be on a seperate thread then the class resetting the
  25. //time would I run into any problems?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement