|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Lockable
Interface for objects synchronized on lock. A class (typically active) implementing this interface allows an application at any time to choose any custom object on which the instance of the class should perform all its synchronization. This is very useful when several stand-alone active objects (with an internal self-synchronization) need to work in a particular synchronous way (without any possibility of dead-lock).
ActivityCore
Method Summary | |
---|---|
java.lang.Object |
getLock()
Just returns the current lock object. |
void |
setLock(java.lang.Object newLock)
Sets new lock object to be used for synchronization. |
Method Detail |
---|
void setLock(java.lang.Object newLock) throws java.lang.NullPointerException
protected transient
and
non-null
, by default lock is set to
this
(during initialization, deserialization or
cloning); all needed synchronization (inside/outside the class)
must be done on lock (as shown below). This method
should be implemented as follows:
protected transient Object lock = this;
public final void setLock(Object newLock)
throws NullPointerException
{ // note: take care on deserializing
Object curLock;
newLock.equals(newLock); // this is a check for null
do
{
synchronized (curLock = lock)
{
if (curLock == lock)
{ // check that synchronized on this lock
lock = newLock; // this is a synchronized operation
break;
}
}
} while (true);
}
newLock
- a lock object (must be non-null
) to be used by
this
object for doing all its synchronization.
java.lang.NullPointerException
- if newLock is null
.getLock()
java.lang.Object getLock()
public final Object getLock()
{
return lock;
}
this
object performs all its synchronization.setLock(java.lang.Object)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |