java - Working of intrensic Lock -


public class check {      public boolean tochange = false;      public synchronized boolean getchange() {         return tochange     }      public synchronized setchange(boolean change) {         this.tochange = change     } } 

when 2 different threads try access , set simultanoesuly , happen in synchronous way due lock on check object?

since both methods non-static , synchronous, no 2 threads @ instance of time, can execute both methods simultaneously, if belong same instance.

so yes, happen in synchronous way, within instances of class.

when create check c = new check();

and 2 threads namely t1, t2 try access c.getchange() , c.setchange() simultaneously, 1 thread given access monitor (which instance c) , other thread has wait until previous thread finishes work , releases monitor.

here instance c default monitor used synchronize access


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -