java::lang::Sync Class Reference

Inheritance diagram for java::lang::Sync:

Inheritance graph
java::awt::Componentjava::awt::event::ActionSourcejava::awt::event::AdjustmentSourcejava::awt::event::AWTEventSourcejava::awt::event::ComponentSourcejava::awt::event::ContainerSourcejava::awt::event::FocusSourcejava::awt::event::HierarchySourcejava::awt::event::ItemSourcejava::awt::ItemCheckablejava::awt::event::KeySourcejava::awt::event::MouseSourcejava::awt::event::PaintSourcejava::awt::event::TextSourcejava::awt::event::WindowSourcejava::awt::MenuComponentjava::net::DatagramPacketjava::util::PropertyChangeSourcejava::util::TimerTaskjava::lang::Lockjava::lang::ScopeAdapterjava::lang::Interfacejava::lang::Objectjava::awt::Buttonjava::awt::Canvasjava::awt::Checkboxjava::awt::Choicejava::awt::Containerjava::awt::Labeljava::awt::ListBoxjava::awt::Scrollbarjava::awt::TextComponentjava::awt::Paneljava::awt::Windowjava::awt::Dialogjava::awt::Framejava::awt::TextAreajava::awt::TextFieldjava::awt::MenuItemjava::awt::CheckboxMenuItemjava::awt::Menujava::awt::MenuBar
[legend]
Collaboration diagram for java::lang::Sync:

Collaboration graph
java::lang::Lockjava::lang::ScopeAdapterjava::lang::Interfacejava::lang::Comparablejava::lang::Objectjava::lang::ObjectRef
[legend]

List of all members.


Detailed Description

The sync interface should be implemented by any class whose instances are intended to be synchronized by a thread.

Author:
Yuh-Jye Chang
Version:
1.21, 02/02/00
Since:
JDK1.0

Public Member Functions

 Sync ()
 Default constructor.
virtual void lock ()
 Lock this object.
virtual void unlock ()
 Unlock this object.
virtual void notify ()
 Wakes up a single thread that is waiting on this object's monitor.
virtual void notifyAll ()
 Wakes up all threads that are waiting on this object's monitor.
virtual void wait (jlong timeout=0)
 Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.

Constructor & Destructor Documentation

java::lang::Sync::Sync (  ) 

Default constructor.


Member Function Documentation

virtual void java::lang::Sync::lock (  )  [virtual]

Lock this object.

Implements java::lang::Lock.

virtual void java::lang::Sync::unlock (  )  [virtual]

Unlock this object.

Implements java::lang::Lock.

virtual void java::lang::Sync::notify (  )  [virtual]

Wakes up a single thread that is waiting on this object's monitor.

If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods.

The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:

Only one thread at a time can own an object's monitor.

Exceptions:
IllegalMonitorStateException if the current thread is not the owner of this object's monitor.

virtual void java::lang::Sync::notifyAll (  )  [virtual]

Wakes up all threads that are waiting on this object's monitor.

A thread waits on an object's monitor by calling one of the wait methods.

The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Exceptions:
IllegalMonitorStateException if the current thread is not the owner of this object's monitor.

virtual void java::lang::Sync::wait ( jlong  timeout = 0  )  [virtual]

Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.

The current thread must own this object's monitor.

This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:

The thread T is then removed from the wait set for this object and re-enabled for thread scheduling. It then competes in the usual manner with other threads for the right to synchronize on the object; once it has gained control of the object, all its synchronization claims on the object are restored to the status quo ante - that is, to the situation as of the time that the wait method was invoked. Thread T then returns from the invocation of the wait method. Thus, on return from the wait method, the synchronization state of the object and of thread T is exactly as it was when the wait method was invoked.

If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.

Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Parameters:
timeout the maximum time to wait in milliseconds.
Exceptions:
IllegalArgumentException if the value of timeout is negative.
IllegalMonitorStateException if the current thread is not the owner of the object's monitor.
InterruptedException if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:42 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3