Java Doc for CyclicBarrier.java in  » Ajax » Laszlo-4.0.10 » EDU » oswego » cs » dl » util » concurrent » 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 » Ajax » Laszlo 4.0.10 » EDU.oswego.cs.dl.util.concurrent 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   EDU.oswego.cs.dl.util.concurrent.CyclicBarrier

CyclicBarrier
public class CyclicBarrier implements Barrier(Code)
A cyclic barrier is a reasonable choice for a barrier in contexts involving a fixed sized group of threads that must occasionally wait for each other. (A Rendezvous better handles applications in which any number of threads meet, n-at-a-time.)

CyclicBarriers use an all-or-none breakage model for failed synchronization attempts: If threads leave a barrier point prematurely because of timeout or interruption, others will also leave abnormally (via BrokenBarrierException), until the barrier is restarted. This is usually the simplest and best strategy for sharing knowledge about failures among cooperating threads in the most common usages contexts of Barriers. This implementation has the property that interruptions among newly arriving threads can cause as-yet-unresumed threads from a previous barrier cycle to return out as broken. This transmits breakage as early as possible, but with the possible byproduct that only some threads returning out of a barrier will realize that it is newly broken. (Others will not realize this until a future cycle.) (The Rendezvous class has a more uniform, but sometimes less desirable policy.)

Barriers support an optional Runnable command that is run once per barrier point.

Sample usage Here is a code sketch of a barrier in a parallel decomposition design.

 class Solver {
 final int N;
 final float[][] data;
 final CyclicBarrier barrier;
 class Worker implements Runnable {
 int myRow;
 Worker(int row) { myRow = row; }
 public void run() {
 while (!done()) {
 processRow(myRow);
 try {
 barrier.barrier(); 
 }
 catch (InterruptedException ex) { return; }
 catch (BrokenBarrierException ex) { return; }
 }
 }
 }
 public Solver(float[][] matrix) {
 data = matrix;
 N = matrix.length;
 barrier = new CyclicBarrier(N);
 barrier.setBarrierCommand(new Runnable() {
 public void run() { mergeRows(...); }
 });
 for (int i = 0; i < N; ++i) {
 new Thread(new Worker(i)).start();
 waitUntilDone();
 }
 }
 

[ Introduction to this package. ]



Field Summary
protected  RunnablebarrierCommand_
    
protected  booleanbroken_
    
protected  intcount_
    
final protected  intparties_
    
protected  intresets_
    

Constructor Summary
public  CyclicBarrier(int parties)
     Create a CyclicBarrier for the indicated number of parties, and no command to run at each barrier.
public  CyclicBarrier(int parties, Runnable command)
     Create a CyclicBarrier for the indicated number of parties.

Method Summary
public  intattemptBarrier(long msecs)
     Enter barrier and wait at most msecs for the other parties()-1 threads. if not timed out, the arrival index: the number of other parties that were still waitingupon entry.
public  intbarrier()
     Enter barrier and wait for the other parties()-1 threads. the arrival index: the number of other parties that were still waitingupon entry.
public synchronized  booleanbroken()
    
protected synchronized  intdoBarrier(boolean timed, long msecs)
    
public  intparties()
    
public synchronized  voidrestart()
     Reset to initial state.
public synchronized  RunnablesetBarrierCommand(Runnable command)
     Set the command to run at the point at which all threads reach the barrier.

Field Detail
barrierCommand_
protected Runnable barrierCommand_(Code)



broken_
protected boolean broken_(Code)



count_
protected int count_(Code)



parties_
final protected int parties_(Code)



resets_
protected int resets_(Code)




Constructor Detail
CyclicBarrier
public CyclicBarrier(int parties)(Code)
Create a CyclicBarrier for the indicated number of parties, and no command to run at each barrier.
exception:
  IllegalArgumentException - if parties less than or equal to zero.



CyclicBarrier
public CyclicBarrier(int parties, Runnable command)(Code)
Create a CyclicBarrier for the indicated number of parties. and the given command to run at each barrier point.
exception:
  IllegalArgumentException - if parties less than or equal to zero.




Method Detail
attemptBarrier
public int attemptBarrier(long msecs) throws InterruptedException, TimeoutException, BrokenBarrierException(Code)
Enter barrier and wait at most msecs for the other parties()-1 threads. if not timed out, the arrival index: the number of other parties that were still waitingupon entry. This is a unique value from zero to parties()-1.If it is zero, then the currentthread was the last party to hit barrier pointand so was responsible for releasing the others.
exception:
  BrokenBarrierException - if any other threadin any previous or current barrier since either creation or the last restartoperation left the barrierprematurely due to interruption or time-out. (If so,the broken status is also set.) Threads that are noticed to have beeninterrupted after being released are not consideredto have broken the barrier.In all cases, the interruptionstatus of the current thread is preserved, so can be testedby checking Thread.interrupted.
exception:
  InterruptedException - if this thread was interruptedduring the barrier. If so, broken status is also set.
exception:
  TimeoutException - if this thread timed out waiting forthe barrier. If the timeout occured while already in thebarrier, broken status is also set.



barrier
public int barrier() throws InterruptedException, BrokenBarrierException(Code)
Enter barrier and wait for the other parties()-1 threads. the arrival index: the number of other parties that were still waitingupon entry. This is a unique value from zero to parties()-1.If it is zero, then the currentthread was the last party to hit barrier pointand so was responsible for releasing the others.
exception:
  BrokenBarrierException - if any other threadin any previous or current barrier since either creation or the last restartoperation left the barrierprematurely due to interruption or time-out. (If so,the broken status is also set.)Threads that are noticied to have beeninterrupted after being released are not consideredto have broken the barrier.In all cases, the interruptionstatus of the current thread is preserved, so can be testedby checking Thread.interrupted.
exception:
  InterruptedException - if this thread was interruptedduring the barrier, and was the one causing breakage. If so, broken status is also set.



broken
public synchronized boolean broken()(Code)



doBarrier
protected synchronized int doBarrier(boolean timed, long msecs) throws InterruptedException, TimeoutException, BrokenBarrierException(Code)



parties
public int parties()(Code)



restart
public synchronized void restart()(Code)
Reset to initial state. Clears both the broken status and any record of waiting threads, and releases all currently waiting threads with indeterminate return status. This method is intended only for use in recovery actions in which it is somehow known that no thread could possibly be relying on the the synchronization properties of this barrier.



setBarrierCommand
public synchronized Runnable setBarrierCommand(Runnable command)(Code)
Set the command to run at the point at which all threads reach the barrier. This command is run exactly once, by the thread that trips the barrier. The command is not run if the barrier is broken.
Parameters:
  command - the command to run. If null, no command is run. the previous command



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.