|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object monitor.AbstractMonitor
public abstract class AbstractMonitor
A class for Monitors. Monitors provide coordination of concurrent threads. Each Monitor protects some resource, usually data. At each point in time a monitor object is occupied by at most one thread.
Use this class as a base class if you can.
Use class
if you are already extending another class.
Monitor
See
C.A.R. Hoare, 'Monitors: an operating system structuring
concept', Communications of the ACM 17, Oct. 1974,
pp. 549-557. Reprinted in C.A.R.Hoare and C.B. Jones,
Essay's in Computing Science, Prentice-Hall, 1989.
and
P. Brinch Hansen, The programming language
Concurrent Pascal, IEEE Transactions on Software
Engineering 1, June 1975, 199-207.
The details of pre- and post-conditions for signal and await and the idea to use a count function come from Ole-Johan Dahl, 'Monitors revisited', in A Classical Mind, A. W. Roscoe (ed.), 1994.
Condition
,
Monitor
Constructor Summary | |
---|---|
protected |
AbstractMonitor()
|
protected |
AbstractMonitor(java.lang.String name)
|
Method Summary | ||
---|---|---|
void |
addListener(MonitorListener newListener)
Register a listener |
|
protected void |
doWithin(java.lang.Runnable runnable)
Run the runnable inside the monitor. |
|
protected
|
doWithin(RunnableWithResult<T> runnable)
Run the runnable inside the monitor. |
|
protected void |
enter()
Enter the monitor. |
|
java.lang.String |
getName()
|
|
protected boolean |
invariant()
The invariant. |
|
protected void |
leave()
Leave the monitor. |
|
protected
|
leave(T result)
Leave the monitor. |
|
protected Condition |
makeCondition()
Create a condition queue with no associated checked Assertion. |
|
protected Condition |
makeCondition(Assertion prop)
Create a condition queue associated with a checked Assertion. |
|
protected Condition |
makeCondition(java.lang.String name)
Create a condition queue with no associated checked Assertion. |
|
protected Condition |
makeCondition(java.lang.String name,
Assertion prop)
Create a condition queue associated with a checked Assertion. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractMonitor()
protected AbstractMonitor(java.lang.String name)
Method Detail |
---|
public java.lang.String getName()
protected boolean invariant()
protected void enter()
A thread must not attempt to enter a Monitor it is already in.
protected void leave()
Only a thread that is in the monitor may leave it.
java.lang.AssertionError
- if the thread that leaves is not the occupant.protected <T> T leave(T result)
Only a thread that is in the monitor may leave it.
java.lang.AssertionError
- if the thread that leaves is not the occupant.protected void doWithin(java.lang.Runnable runnable)
Any thread calling this method will be delayed until the monitor is empty. The "run" method of its argument is then executed within the protection of the monitor.
When the run method returns, if the thread still occupies the monitor, it leaves the monitor.
runnable
- A Runnable object.protected <T> T doWithin(RunnableWithResult<T> runnable)
Any thread calling this method will be delayed until the monitor is empty. The "run" method of its argument is then executed within the protection of the monitor.
When the run method returns, if the thread still occupies the monitor, it leaves the monitor.
Thus the signalAndLeave method may be called within the run method.
runnable
- A RunnableWithResult object.
protected Condition makeCondition(Assertion prop)
protected Condition makeCondition()
protected Condition makeCondition(java.lang.String name, Assertion prop)
protected Condition makeCondition(java.lang.String name)
public void addListener(MonitorListener newListener)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |