Java Doc for RWLock.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » com » sun » media » jai » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » com.sun.media.jai.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.sun.media.jai.util.RWLock

RWLock
final public class RWLock (Code)
A class that provides a classic reader/writer lock functionality. This implementation is based on the JavaWorld article by Tark Modi titled "Lock on to an alternate synchronized mechanism" with some minor modifications.

This lock provides the following functionality :

  • Allows multiple threads read access while only a single thread can have a write access.
  • Allows a thread owning a read lock to "upgrade" to a write lock.
  • Allows a thread owning a write lock to "downgrade" to a read lock.
  • Allows the option to either block or specify a waitTime on certain requests.

Inner Class :public class UpgradeNotAllowed extends RuntimeException
Inner Class :public class LockNotHeld extends RuntimeException


Constructor Summary
public  RWLock(boolean allowUpgrades)
     Constructor.
public  RWLock()
     Constructor.

Method Summary
public synchronized  booleandowngrade()
     Tries to downgrade a write lock to a read lock.
public synchronized  booleanforReading(int waitTime)
     Tries to obtain a read lock within the specified time.
Parameters:
  waitTime - the time to wait in milliseconds while tryingto obtain the read lock.
public synchronized  booleanforReading()
     Tries to obtain a read lock.
public synchronized  booleanforWriting(int waitTime)
     Tries to obtain a write lock withing the specified time.
public synchronized  booleanforWriting()
     Tries to obtain a write lock.
public synchronized  voidrelease()
     Tries to relinquish the ownership of a lock.
public synchronized  booleanupgrade(int waitTime)
     Try to upgrade a write lock within the specified amount of time.
public synchronized  booleanupgrade()
     Tries to upgrade to a write lock.


Constructor Detail
RWLock
public RWLock(boolean allowUpgrades)(Code)
Constructor.
Parameters:
  should - upgrades of read locks to write locks beallowed ?



RWLock
public RWLock()(Code)
Constructor. Equivalent to RWLock(true) which creates an upgradable reader-writer lock.




Method Detail
downgrade
public synchronized boolean downgrade() throws LockNotHeld(Code)
Tries to downgrade a write lock to a read lock. If the current thread does not hold the lock an exception is thrown. If the current thread already owns a read lock, nothing happens. If it owns a write lock, then it is downgraded to a read lock. All threads waiting for a read lock can now get it only if there are no other threads waiting for a write lock ahead of them. true if the downgrade was performed successfully.
throws:
  LockNotHeld - if the current thread does not own the lock.



forReading
public synchronized boolean forReading(int waitTime)(Code)
Tries to obtain a read lock within the specified time.
Parameters:
  waitTime - the time to wait in milliseconds while tryingto obtain the read lock. A negative value indicates ablocking wait. true if the read lock was obtained without timing out.



forReading
public synchronized boolean forReading()(Code)
Tries to obtain a read lock. Equivalent to forReading(-1) which will go into a blocking wait attempting to get a read lock. true, always.



forWriting
public synchronized boolean forWriting(int waitTime) throws UpgradeNotAllowed(Code)
Tries to obtain a write lock withing the specified time. If the current thread owns a read lock, then it is upgraded to a write lock if upgrades are allowed, else, throws an UpgradeNotAllowed exception. If the lock is not owned by the current thread then it waits for a write lock for the specified time.
Parameters:
  waitTime - the time to wait in milliseconds while tryingto obtain the write lock. A negative value indicates ablocking wait. true if the write lock was obtained without timing out.
throws:
  UpgradeNotAllowed - if current thread owns a read lockand upgrades are not allowed.



forWriting
public synchronized boolean forWriting() throws UpgradeNotAllowed(Code)
Tries to obtain a write lock. Equivalent to forWriting(-1) which will go into a blocking wait attempting to get a write lock. true, always.
throws:
  UpgradeNotAllowed - if current thread owns a read lockand upgrades are not allowed.



release
public synchronized void release() throws LockNotHeld(Code)
Tries to relinquish the ownership of a lock. If the current thread does not hold the lock an exception is thrown. Note that every call to forReading and forWriting must have a corresponding release() call. However, upgrade() and downgrade() do not have corresponding release() calls.
throws:
  LockNotHeld - if the current thread does not own the lock.



upgrade
public synchronized boolean upgrade(int waitTime) throws UpgradeNotAllowed, LockNotHeld(Code)
Try to upgrade a write lock within the specified amount of time. If the current thread does not own the lock or if upgrades are not allowed an exception is thrown. If the current thread already owns a write lock, nothing happens. Otherwise, threads already owning a read lock are given a higher priority in receiving the write lock than those that own no lock.
Parameters:
  waitTime - the time to wait in milliseconds while tryingto upgrade to a write lock. A negative value indicates ablocking wait. true if the upgrade was performed without timing out.
throws:
  LockNotHeld - if the current thread does not own the lock
throws:
  UpgradeNotAllowed - if the lock is not currentlyheld by the owner.



upgrade
public synchronized boolean upgrade() throws UpgradeNotAllowed, LockNotHeld(Code)
Tries to upgrade to a write lock. Equivalent to upgrade(-1) which will go into a blocking wait attempting to get a upgrade to a write lock. true, always.
throws:
  LockNotHeld - if some other thread owns the lock
throws:
  UpgradeNotAllowed - if the lock is not currentlyheld by the owner.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.