blob: 884da488fbeb0d01a5c5af470f53b50996f4a4db [file] [log] [blame]
/*
* Copyright (c) 2017 CEA.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* CEA - initial API and implementation
*/
package org.eclipse.sensinact.gateway.sthbnd.inovallee;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class Periodic {
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final ScheduledFuture<?> handle;
public Periodic(Runnable run, long initialDelay, long period, TimeUnit unit) {
handle = scheduler.scheduleAtFixedRate(run, initialDelay, period, unit);
}
public void stop() {
handle.cancel(true);
}
}