multithreading - Object intrinsic monitor as java.util.concurrent.Lock -


i believe useful able use object's monitor lock. :

synchronized(object) {     ... } 

would equivalent :

lock.lock(); try {     ... } {     lock.unlock(); } 

as far understand it, not possible achieve using lock interface since synchronization happens in blocks. solution see have java.lang.object enriched method

public lock aslock/getintrinsicmonitorobject(); // name isn't perfect i'm not asking 

or :

locksupport.getintrinsicmonitorobject(object of); 

questions :

  • is there reasons isn't possible (i consider fact trylock isn't possible synchronization isn't one)

  • is there solution using existing jre classes ?

  • would jsr on make sense ?

the unsafe class* has support directly manipulate monitors:

public native void monitorenter(object o);  public native void monitorexit(object o);  public native boolean trymonitorenter(object o); 

*that's in java 8 think there in java 7


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -