FileDocCategorySizeDatePackage
CondVar.javaAPI DocExample4279Thu Mar 11 22:31:00 GMT 2004javathreads.examples.appa

CondVar

public class CondVar extends Object

Fields Summary
private BusyFlag
SyncVar
Constructors Summary
public CondVar()

                this(new BusyFlag());
        
public CondVar(BusyFlag sv)

                SyncVar = sv;
        
Methods Summary
public synchronized voidcvBroadcast(BusyFlag sv)

                // You must own the lock in order to use this method
                if (sv.getBusyFlagOwner() != Thread.currentThread()) {
                        throw new IllegalMonitorStateException("current thread not owner");
                }
                notifyAll();
        
public voidcvBroadcast()

                cvBroadcast(SyncVar);
        
public voidcvSignal()

                cvSignal(SyncVar);
        
public synchronized voidcvSignal(BusyFlag sv)

                // You must own the lock in order to use this method
                if (sv.getBusyFlagOwner() != Thread.currentThread()) {
                        throw new IllegalMonitorStateException("current thread not owner");
                }
                notify();
        
public voidcvTimedWait(int millis)

                cvTimedWait(SyncVar, millis);
        
public voidcvTimedWait(BusyFlag sv, int millis)

                int i = 0;
                InterruptedException errex = null;

                synchronized (this) {
                        // You must own the lock in order to use this method
                        if (sv.getBusyFlagOwner() != Thread.currentThread()) {
                                throw new IllegalMonitorStateException("current thread not owner");
                        }

                        // Release the lock (Completely)
                        while (sv.getBusyFlagOwner() == Thread.currentThread()) {
                                i++;
                                sv.freeBusyFlag();
                        }
                
                        // Use wait() method        
                        try {
                                if (millis == 0) {
                                        wait();
                                } else {
                                        wait(millis);
                                }
                        } catch (InterruptedException iex) {
                                errex = iex;
                        }
                }
         
                // Obtain the lock (Return to original state)
                for (; i>0; i--) {
                        sv.getBusyFlag();
                }

                if (errex != null) throw errex;
                return;
        
public voidcvWait()

                cvTimedWait(SyncVar, 0);
        
public voidcvWait(BusyFlag sv)

                cvTimedWait(sv, 0);