Monday, June 20, 2011

Interfaces in java concurrency utils

Java’s concurrency library, java.util.concurrent, has a variety of useful classes to make concurrent code easier to write and more reliable. (If you’re not familiar with that library, you’ll find this post a lot more comprehensible if you read Sun’s tutorial on concurrency.)
There are many ways to put the various building blocks that java.util.concurrent (j.u.c from now on) provides to create concurrent systems. Before we begin, here’s a short reminder of what the most basic j.u.c classes and interfaces are.


Runnable
Intended to be more or less equivalent to starting a Thread. It defines a method that does not return anything and cannot throw checked exceptions.
Callable
A more flexible variant of the same idea. It defines a method that can return a value and throw a checked exception.
Future
Represents the result of a computation (e.g. a Callable). It is used in place of a value that may not be computed yet.
Executor
Accepts Runnables and returns void.
ExecutorService
Extends Executor to also provide a method that accepts a Callable and returns a Future.
Executors
Provides simple methods to get common types of ExecutorService implementations.
Some of them are:
CompletionService

No comments:

Post a Comment

Chitika