Saturday, 24 January 2009

Getting Groovy with SwingWorker TV

javax.swing.SwingWorker is the generic type for SwingWorker, which came in Java 1.6. Various incarnations of the SwingWorker existed prior to 1.6 though. T is the result type returned by various methods, and V is the type used for carrying out various intermediate results. The class implements the RunnableFuture interface.

The primary purpose of a SwingWorker is to do lengthy GUI-interacting tasks in a dedicated thread. Subclasses of SwingWorker must implement the doInBackground() method to perform background computation.

The concept of a Future<V> is an asynchronous computation. Methods exist to check if the computation is complete, to wait for completion and retrieve the result of the computation.

A FutureTask<V> is a cancellable asynchronous computation. This class also implements the RunnableFuture interface.

No comments: