Hi so I have repetitive Code and want to get rid of it.
I want to get rid of the scheduler call (scheduler.schedule(this::transition, 10, TimeUnit.SECONDS);) because its copy paste code. But I dont know how to put it in an Abstract Class so that it will be executed properly in every Stage. The "this::transition" makes it impossible for me.
public class Stage1 {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
public void transition() {
...
scheduler.schedule(this::transition, 10, TimeUnit.SECONDS);
}
}
public class Stage2 {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
public void transition() {
...
scheduler.schedule(this::transition, 10, TimeUnit.SECONDS);
}
}
public class Stage3 {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
public void transition() {
...
scheduler.schedule(this::transition, 10, TimeUnit.SECONDS);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…