doDatabaseThing();
} catch (InterruptedException ie) {
return;
}
guess = r.nextInt()% 10;
cancel.incrementGuesses();
if (guess == target) {
synchronized(cancel) {
System.out.println(self.getName() +
" got the answer: " + guess);
if (cancel.found) {
System.out.println(self.getName() +
" too late! Exiting");
return;
// If someone else already found
it...
}
cancel.found = true;
for (int j = 0; j < cancel.nSearchers; j++) {
TSDThread t1 = (TSDThread) cancel.threads[j];
if (!t1.equals(self)) {  // Don't kill
yourself
synchronized (t1) {
while (t1.inCriticalSection) {
try  {
t1.wait();
} catch (InterruptedException ie)
{
// Impossible
}
}
t1.interrupt();
if (Cancellation.DEBUG) {
System.out.println(self.getName()
+
" cancelling " +
t1.getName());
}
}
}
}
cancel.answer = guess;
System.out.println(self.getName() + " done.");
return;
}
}
}
}
}
// CancellationInterrupt/TSDThread.java
/*
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home