java - What really is Atomic? -


what atomic? since have choose language frame question more choose java. know atomic means or rollback/do nothing. have following

public class myclass {      private boolean progress;      public void setprogress(boolean progress) {         this.progress = progress;     }      public boolean getprogress() {        return progress;     }  } 

now of following thread-safe or atomic or both ? please treat each new line separate piece of code

     -------------------      getprogress(); //       ------------------       ----------------------      setprogress(true); //      ----------------------       -------------------      getprogress()      setprogress();      -------------------       --------------------      setprogress();      getprogress();      -------------------- 

which of these cases make sense use atomicreference in java?

from this:

what operations in java considered atomic?

i'd none of them atomic, since function call not atomic operation. once in function, assigning boolean atomic (just line), returning isn't.

for thread safety take @ this:

are java getters thread-safe?

basically old value of "progress" maybe cached inside cpu, if assigning new value atomic (just = line again) without synched assignment (atomicboolean or synchronized getter/setter) thread-safe there can memory consistency errors may want declare variable volatile other threads can see updated value.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -