[concurrency-interest] ScheduledThreadPoolExecutor woes

Hanson Char hanson.char at gmail.com
Sun Feb 4 20:58:14 EST 2007


Once I fixed the code to compile under jdk1.6, it would no longer compile
under 1.5, and vice-versa.  Good enough for me for now.

Hanson

On 2/3/07, Hanson Char <hanson.char at gmail.com> wrote:
>
> Interesting that the code compiles by javac 1.5.0_10, but not by javac
> 1.6.0 with the following compilation error, after I tried to "fill in the
> blank" by creating an AbstractRetryPolicy.java (see below.)
>
> RetryPolicies.java:181: <anonymous RetryPolicies$5> is not abstract and
> does not override abstract method <T>invokeAny(java.util.Collection<?
> extends
> java.util.concurrent.Callable<T>>,long,java.util.concurrent.TimeUnit ) in
> java.util.concurrent.ExecutorService
>     return new ExecutorService() {
>                                  ^
> 1 error
>
> Any idea if this should or should not compile ?  If it should not, how it
> can be fixed ?  If it should, is that a compiler bug in jdk1.6.0 ?
>
> Hanson
>
> public abstract class AbstractRetryPolicy implements RetryPolicy
> {
>     public Class<? extends Exception>[] recoverableExceptions;
>
>     public AbstractRetryPolicy(Class<? extends Exception>[]
> recoverableExceptions)
>     {
>         this.recoverableExceptions = recoverableExceptions;
>     }
>
>     public abstract long nextDelay(long startTime, int retries);
>
>     public boolean isFailureRecoverable(Exception e)
>     {
>         for (Class<? extends Exception> c : recoverableExceptions)
>             if (c.isAssignableFrom(e.getClass()))
>                 return true;
>         return false;
>     }
> }
> On 2/3/07, Hanson Char <hanson.char at gmail.com> wrote:
> >
> > Hi Tim,
> >
> > >Josh told me he'd be willing to distribute this more widely if there
> > was sufficient interest.
> >
> > I am very interested in the retry policy code.
> >
> > >I've placed an incomplete draft of this code in a public area of the Java
> > Concurrency in Practice source repository:
> >
> > Any chance I can find the missing pieces ?
> >
> > Thanks in advance.
> >
> > Hanson
> >
> > On 1/20/07, Tim Peierls <tim at peierls.net> wrote:
> > >
> > > Last spring Josh Bloch proposed an interface and some standard
> > > implementations to capture something like what Bela described.
> > >
> > > public interface RetryPolicy {
> > >     boolean isFailureRecoverable(Exception e);
> > >     long nextDelay(long startTime, int retries);
> > > }
> > >
> > > The implementations included exponential backoff, truncated
> > > exponential backoff, and fixed delay.
> > >
> > > There was also a factory method for an ExecutorService wrapper to wrap
> > > Runnables and Callables with the machinery needed to implement a given
> > > RetryPolicy.
> > >
> > > The idea is that a task signals that it may be retried by throwing an
> > > exception e for which RetryPolicy.isFailureRecoverable(e) is true, and
> > > the nextDelay method decides, based on the start time of the initial attempt
> > > and the number of retries that have occurred, how long to wait before trying
> > > again. A negative return from nextDelay means not to try again, in which
> > > case the most recent failure exception is rethrown.
> > >
> > > For example, a policy of incessant retrying would be expressed by:
> > >
> > > class IncessantRetrying implements RetryPolicy {
> > >     public boolean isFailureRecoverable(Exception e) { return true; }
> > >     long nextDelay(long startTime, int retries) { return 0; }
> > > }
> > >
> > > Josh told me he'd be willing to distribute this more widely if there
> > > was sufficient interest.
> > >
> > > I've placed an incomplete draft of this code in a public area of the Java
> > > Concurrency in Practice source repository:
> > >
> > > https://dev.priorartisans.com/repos/jcip/trunk/src/main/jcip/retry/
> > >
> > > It's incomplete because it doesn't define AbstractRetryPolicy.
> > >
> > > What Bela describes is slightly different: each task can be submitted
> > > with its own "RetryPolicy". That could be achieved within Josh's framework,
> > > for example, by extending ScheduledThreadPoolExecutor and overriding
> > > decorateTask to do the requisite wrapping for tasks that implement
> > > RetryPolicy.
> > >
> > > --tim
> > >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20070204/b2285e51/attachment.html 


More information about the Concurrency-interest mailing list