[concurrency-interest] differentiating between result-bearing and non- result-bearing actions

Gary Moyer notgermy@yahoo.com
Fri, 16 Jan 2004 15:48:34 -0800 (PST)


I believe there is a problem with the overloaded use of Future.  From the
Future javadoc:

If you would like to use a Future for the sake of cancellability but not
provide a usable result, you can declare types of the form Future<?> and return
null as a result of the underlying task.

Thus Future.get() returns null when the instance is returned by any of the
following ScheduledExecutorService methods:

1: schedule(Runnable command, long delay, TimeUnit unit)
2: scheduleAtFixedRate(Runnable command, ...)
3: scheduleWithFixedDelay(Runnable command, ...)

What's confusing is null may likewise represent a "usable" result.  While it is
possible (but klunky) to determine the usable-ness of the result with cases 2
and 3, e.g.

    [NOTE: example assumes isDone() always returns false if task is repeating]

    Object result = future.get();
    if (result == null && future.isDone() == false) {
        // no result
    }

it is not possible to with case 1.

I would ask that if Future is going to be used in this capacity then it should
also provide a method to indicate the usable-ness of the result.

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus