All Downloads are FREE. Search and download functionalities are using the official Maven repository.

be.bagofwords.application.BowTaskScheduler Maven / Gradle / Ivy

Go to download

Utility classes that are used in the count-db project and other bow-* projects

The newest version!
package be.bagofwords.application;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by Koen Deschacht ([email protected]) on 14/11/14.
 */

public class BowTaskScheduler implements CloseableComponent {

    private ScheduledExecutorService scheduledExecutorService;

    /**
     * @param task
     * @param period In milliseconds
     */

    public synchronized void schedulePeriodicTask(Runnable task, long period) {
        if (scheduledExecutorService == null) {
            scheduledExecutorService = Executors.newScheduledThreadPool(5);
        }
        scheduledExecutorService.scheduleAtFixedRate(task, 0, period, TimeUnit.MILLISECONDS);
    }

    @Override
    public void terminate() {
        scheduledExecutorService.shutdown();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy