import java.util.ArrayList; import java.util.List; public class Searcher { private boolean isDone = false; public void doFederatedSearch() { List searchers = new ArrayList(); // add each searcher... perhaps the real instances will // be different extensions of the base class, or maybe all // the same but with different parameters. // start each searcher for (SearchThread searcher : searchers) { searcher.start(); } // wait 10 seconds try { Thread.sleep(10000); } catch (InterruptedException ex) { // didn't wait the entire timeout period because // it was interrupted by another thread. } // disallow further additions to the list synchronized (this) { isDone = true; } // get (and presumably show) the consolidated list this.getConsolidatedList(); } private synchronized void addSearchResults(List results) { if (!isDone) { // TODO: add the actual code to add the search results, which // most likely won't be in the form of a list of Strings. } else { System.out.println("These results came in too late and will be ignored!"); } } private synchronized void getConsolidatedList() { // get the list... this must be synchronized with // addSearchResults to eliminate concurrency issues } private class SearchThread extends Thread { public void run() { // TODO: perform the search here and pass the results // back to the main class for consolidation addSearchResults(null); // this should contain the actual parsed results } } }