callable tasks, simple thread pool set-up, shutdown, awaitTermination

What you added to task queue should not be a simple POJO or java bean. It needs a run() or call() method.

public class DualThreadPool {
//* Construct a thread pool (size 2) with an internal unbounded queue
private final ExecutorService eService = Executors.newFixedThreadPool(2);
private void addTask(Callable task) {
assert task != null;
this.eService.submit(task);
}
public static void main(String adfs32[]) throws FileNotFoundException, InterruptedException {
DualThreadPool pool = new DualThreadPool();
pool.addTask(new FileParserTask(Downloader.download("<a href="http://www.google.com/" target="_blank">http://www.google.com/</a>", ""), true));
pool.addTask(new FileParserTask(new FileReader("c:/windows/ie7.log")));
pool.eService.shutdown();
pool.eService.awaitTermination(22, TimeUnit.SECONDS);
MultiCounter.instance.dumpCounts();
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s