I have a class called "Scheduler":
package Modelo;
import java.util.ArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
*
* @author Juan Cruz
*/
public class Scheduler implements Runnable{
private Runnable task;
private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
public Scheduler(Runnable task, ScheduledExecutorService executorService) {
this.task = task;
this.executorService = executorService;
}
public void sesionesAbiertas() {
Runnable beeper = new Runnable() {
public void run() {
/* Code */
}
}
};
ScheduledFuture<?> beeperHandle = executorService.scheduleAtFixedRate(beeper, 10, 10, TimeUnit.SECONDS);
executorService.schedule(new Runnable() {
public void run() {
beeperHandle.cancel(true);
}
}, 60 * 60, TimeUnit.SECONDS);
}
@Override
public void run() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
The problem is that it is never executed and I don't know what to do to call it the first time, so it starts executing the code every 10 seconds (as you can see in executorService)
I think I am missing something to call you for the first time but I have read the documentation and I cannot find what is missing
EDIT: I try delete "implements Runnable" in the name of the class and deleting the last function "@override public void run()"