将 Runnable 实现到接口中的抽象 class

Abstract class that implements Runnable into interface

如何将实现 Runnable 的抽象 class 重构为接口?

import com.codahale.metrics.health.HealthCheck;

public abstract class ApplicationProcessor implements Runnable {

    public abstract HealthCheck getHealthCheck();
}

更新:以及我如何才能在将来删除通用通配符类型的使用?

import io.dropwizard.lifecycle.Managed;
import java.util.concurrent.Future;
import com.codahale.metrics.health.HealthCheck;

public class ManagedBean extends HealthCheck implements Managed {

    private final String name;
    private final ManagedThreadPool threadPool;
    private final ApplicationProcessor processor;
    private Future<?> future; // HERE sonarqube complains..

    public ManagedBean( String name, ManagedThreadPool threadPool, ApplicationProcessor processor ) {
        this.name = name;
        this.threadPool = threadPool;
        this.processor = processor;
    }

    @Override
    public void start() throws Exception {
        future = threadPool.submit( processor );
    }

    @Override
    public void stop() throws Exception {
        if ( !future.isDone() ) {
            future.cancel( true );
        }
    }

    @Override
    protected Result check() throws Exception {
        return processor.getHealthCheck().execute();
    }

}

谢谢

public interface ApplicationProcessor extends Runnable {
    // interface methods are by default public and abstract
    HealthCheck getHealthCheck();
}

至于第二部分使用

Future<Void> or just Future