blackh Sun Nov 30 22:27:10 2003 EDT
Modified files:
/grapevine/raisen/grapevine version.xml
/grapevine/test-client Universe.java
Log:
Index: grapevine/test-client/Universe.java
diff -u grapevine/test-client/Universe.java:1.3 grapevine/test-client/Universe.java:1.4
--- grapevine/test-client/Universe.java:1.3 Mon Nov 4 02:51:53 2002
+++ grapevine/test-client/Universe.java Sun Nov 30 22:27:10 2003
@@ -39,6 +39,9 @@
listeners.remove(listener);
}
+ private static final int maxThreads = 6;
+ private int noOfThreads;
+
public void run()
{
try {
@@ -53,10 +56,17 @@
toVisit.wait();
for (int i = 0; i < toVisit.size(); i++) {
final Node node = (Node) toVisit.elementAt(i);
+ // Hold off if there are too many threads running at once.
+ while (noOfThreads > maxThreads)
+ toVisit.wait();
new Thread() {
public void run()
{
try {
+ synchronized (toVisit) {
+ noOfThreads++;
+ }
+
// Retrieve the neighbours from the network
System.out.println("Retrieving neighbours for " + node);
List neighbours = node.getNeighbours();
@@ -75,6 +85,12 @@
}
catch (IOException e) {
System.err.println(e.toString());
+ }
+ finally {
+ synchronized (toVisit) {
+ noOfThreads--;
+ toVisit.notify();
+ }
}
}
}.start();
|