org.inria.ns.reflex.structures
Interface Lockable

All Known Implementing Classes:
XPathFilter

public interface Lockable

A non deadlock-prone lockable object on behalf of a thread that can be suspended and resumed.

Concrete implementations must not use the deprecated methods. For this purpose, the prudent approach is to have the "target thread" poll an internal variable indicating the desired state of the thread(active or suspended).

To suspend/resume a thread safely, use the inner class Monitor.

Author:
Philippe Poulard
See Also:
Lockable.Monitor

Nested Class Summary
static class Lockable.Monitor
          A Monitor that suspends and resumes Threads thanks to Lockables.
 
Method Summary
 boolean isSleeping()
          Indicates whether the thread that owns this lockable is sleeping or not.
 void resumeThread()
          Resumes safely the thread that owns this lockable.
 void suspendThread()
          Suspends safely the current thread.
 

Method Detail

suspendThread

void suspendThread()
                   throws InterruptedException
Suspends safely the current thread.

A concrete implementation MUST NOT use Thread.suspend().

A typical implementation is like as follow :

    public synchronized void suspendThread() {
        this.sleeping = true;
        this.wait();
    }

Throws:
InterruptedException - When the current thread is interrupted.

resumeThread

void resumeThread()
Resumes safely the thread that owns this lockable.

A concrete implementation MUST NOT use Thread.resume().

A typical implementation is like as follow :

    public synchronized void resumeThread() {
        this.sleeping = false;
        this.notify();
    }


isSleeping

boolean isSleeping()
Indicates whether the thread that owns this lockable is sleeping or not.

Returns:
true if the owner thread is sleeping, false otherwise.