KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > standalone > jvm > Barrier


1 /*
2  * 00/08/01 @(#)Barrier.java 1.3 Copyright (c) 2000 Sun Microsystems, Inc. All
3  * Rights Reserved. Sun grants you ("Licensee") a non-exclusive, royalty free,
4  * license to use, modify and redistribute this software in source and binary
5  * code form, provided that i) this copyright notice and license appear on all
6  * copies of the software; and ii) Licensee does not utilize the software in a
7  * manner which is disparaging to Sun.
8  */

9
10 package org.objectweb.cjdbc.scenario.standalone.jvm;
11
12 public class Barrier
13 {
14
15   private int m_numThreads = 0;
16   private int m_currentCount = 0;
17
18   public Barrier(int numThreads)
19   {
20     m_numThreads = numThreads;
21   }
22
23   public void waitForGo()
24   {
25     synchronized (this)
26     {
27       m_currentCount++;
28       if (m_currentCount < m_numThreads)
29       {
30         try
31         {
32           wait();
33         }
34         catch (InterruptedException JavaDoc exp)
35         {
36           System.out.println("Barrier caught interrupted exception!");
37         }
38       }
39       else
40         notifyAll();
41     }
42   }
43
44 }
Popular Tags