java - Understanding synchronized blocks -


i have problem understanding why better use synchronized(syncobject) synchronized(this). example, class:

public class pool implements objectpool {     private object[] pool;     private int initialcapacity;     private int available = 0;     private int waiting = 0;     private final object syncobject = new object();      public pool(int initialcapacity) {         this.initialcapacity = initialcapacity;         pool = new object[initialcapacity];      }      public void releaseobject(object o) throws exception {         synchronized (syncobject) {             pool[available] = o;             available++;         }          if (waiting > 0) {             notify();         }     } } 

because if use this, thread trying execute method have wait, whereas if use object lock, restrict critical section.


Comments

Popular posts from this blog

Linux vanilla kernel on QEMU and networking with eth0 -

rdbms - what exactly the undo information lives in oracle? -

clojure - 'get' replacement that throws exception on not found? -