You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
package app.updates;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.function.Supplier;
|
|
|
|
public abstract class BaseUpdater {
|
|
private final Logger logger = LoggerFactory.getLogger(BaseUpdater.class);
|
|
|
|
public void CreateTaskUpdater(Supplier function, int timeout) {
|
|
logger.warn("Create task: {}, update every {} seconds", function.toString(), timeout / 1000);
|
|
Executors.newFixedThreadPool(1).submit(() -> {
|
|
while (true) {
|
|
try {
|
|
//System.out.printf("Call: %s\n", function.toString());
|
|
function.get();
|
|
} catch (Exception err) {
|
|
err.printStackTrace();
|
|
} finally {
|
|
try {
|
|
Thread.sleep(timeout);
|
|
} catch (InterruptedException e) {}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|