站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

PriorityMutex (Editor Utilities) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.util/1 1.17

org.netbeans.lib.editor.util
Class PriorityMutex

java.lang.Object
  extended by org.netbeans.lib.editor.util.PriorityMutex

public class PriorityMutex
extends Object

Mutex that allows only one thread to proceed other threads must wait until that one finishes.
The thread that "holds" the mutex (has the mutex access granted) may reenter the mutex arbitrary number of times (just increasing a "depth" of the locking).
If the priority thread enters waiting on the mutex then it will get serviced first once the current thread leaves the mutex.


Constructor Summary
PriorityMutex()
           
 
Method Summary
 Thread getLockThread()
          Return a thread that acquired this mutex.
protected  boolean isPriorityThread()
          Return true if the current thread that is entering this method is a priority thread and should be allowed to enter as soon as possible.
 boolean isPriorityThreadWaiting()
          Can be called by the thread that acquired the mutex to check whether there is a priority thread (such as AWT event-notification thread) waiting.
 void lock()
          Acquire the ownership of the mutex.
 void unlock()
          Release the ownership of the mutex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityMutex

public PriorityMutex()
Method Detail

lock

public void lock()
Acquire the ownership of the mutex.

The following pattern should always be used:

   mutex.lock();
   try {
       ...
   } finally {
       mutex.unlock();
   }
 


unlock

public void unlock()
Release the ownership of the mutex.

See Also:
lock()

isPriorityThreadWaiting

public boolean isPriorityThreadWaiting()
Can be called by the thread that acquired the mutex to check whether there is a priority thread (such as AWT event-notification thread) waiting.
If there is a priority thread waiting the non-priority thread should attempt to stop its work as soon and release the ownership of the mutex.
The method must *not* be called without first taking the ownership of the mutex (it is intentionally not synchronized).


getLockThread

public final Thread getLockThread()
Return a thread that acquired this mutex.
This method is intended for diagnostic purposes only.

Returns:
thread that currently acquired lock the mutex or null if there is currently no thread holding that acquired this mutex.

isPriorityThread

protected boolean isPriorityThread()
Return true if the current thread that is entering this method is a priority thread and should be allowed to enter as soon as possible.

The default implementation assumes that SwingUtilities.isEventDispatchThread() is a priority thread.

Returns:
true if the entering thread is a priority thread.

org.netbeans.modules.editor.util/1 1.17

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.