[concurrency-interest] Fwd: ScheduledThreadPoolExecutor woes

Rémi Forax forax at univ-mlv.fr
Tue Feb 13 16:46:23 EST 2007


Hanson Char a écrit :
> AbstractRetryPolicy has no problem compiling in Java 5 and 6, it's the 
> RetryPolicies that is having problem.  See below my reversed engineered 
> version of AbstractRetryPolicy.
> 
> I also put it under package net.jcip.retry , instead of the default 
> namespace.
> 
> H
> 
> package net.jcip.retry;
> 
> /**
>  * @author Josh Bloch
>  * @author Hanson Char - fill in the missing pieces
>  */
> // https://dev.priorartisans.com/repos/jcip/trunk/src/main/jcip/retry/
> public abstract class AbstractRetryPolicy implements RetryPolicy
> {
>     private final 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;
>     }
> }
> 

I think your code is not useable,
even if the way you use your array of recoverable exceptions is safe,
there is no way to create such array without a warning.
And there is no typesafe array in Java:
(see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4888066)

Arrays of parametrized type are rarely safe,
in my opinion, the only way to safely create an array of parametrized 
wilcard is to create a non generics subclass.

enum Foo {
   bar;
}
...
Enum<? extends Foo>[] foos = Foo.values();

Here foos is created without an unsafe warning.
But in your case java.lang.Class is final.

How do you expect to use your constructor ?

cheers,
Rémi Forax






More information about the Concurrency-interest mailing list