Example usage for java.util.concurrent Executors newSingleThreadScheduledExecutor

List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor

Introduction

In this page you can find the example usage for java.util.concurrent Executors newSingleThreadScheduledExecutor.

Prototype

public static ScheduledExecutorService newSingleThreadScheduledExecutor() 

Source Link

Document

Creates a single-threaded executor that can schedule commands to run after a given delay, or to execute periodically.

Usage

From source file:com.ms.commons.udas.impl.commons.MemcachedKeyStore.java

@SuppressWarnings("unused")
private void createThreadPool() {
    int periodInSenconds = 600;// 
    String period = System.getProperty("memcached.key.flush.time");
    logger.error("memcached.key.flush.time period : " + period);
    if (period != null) {
        int temp = NumberUtils.toInt(period);
        if (temp > 0) {
            periodInSenconds = temp;/*from   w  ww.j a va 2s.  c  o  m*/
        }
    }
    logger.error("Used: memcached.key.flush.time " + periodInSenconds + " Sendconds");

    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    executor.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            flushKeyIfNecesery();
        }
    }, 1, periodInSenconds, TimeUnit.SECONDS);
}

From source file:org.cloudifysource.rest.repo.UploadRepo.java

private void createScheduledExecutor() {
    final CleanUploadDirRunnable cleanupThread = new CleanUploadDirRunnable(restUploadDir,
            cleanupTimeoutMillis);/*w w  w . j  av  a 2s  .  c  om*/
    executor = Executors.newSingleThreadScheduledExecutor();
    try {
        executor.scheduleAtFixedRate(cleanupThread, 0, cleanupTimeoutMillis, TimeUnit.MILLISECONDS);
    } catch (RejectedExecutionException e) {
        logger.log(Level.WARNING, "failed to scheduled for execution - " + e.getMessage());
        throw e;
    }
}

From source file:ro.startx.ups.server.Sender.java

@VisibleForTesting
public Sender(int retryCount, String url) {
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();

    this.url = url;

    this.client = HttpAsyncClients.custom().setMaxConnTotal(100).setMaxConnPerRoute(10).build();

    this.executor = new AsyncRetryExecutor(scheduler).retryOn(ServerFailedException.class)
            .retryOn(TimeoutException.class).retryOn(IOException.class).withExponentialBackoff(100, 2.0)
            .withUniformJitter().withMaxDelay(4000).withMaxRetries(retryCount);

    this.client.start();
}

From source file:cn.scala.es.HeartBeat.java

void start() {
    scheduler = Executors.newSingleThreadScheduledExecutor();
    if (log != null && log.isTraceEnabled()) {
        log.trace(String.format("Starting heartbeat for %s", id));
    }//from  w w w .j  a v a  2  s  . c  o  m

    scheduler.scheduleWithFixedDelay(new Runnable() {
        @Override
        public void run() {
            if (log != null && log.isTraceEnabled()) {
                log.trace(String.format("Heartbeat/progress sent to Hadoop for %s", id));
            }
            progressable.progress();
        }
        // start the reporter before timing out
    }, delay.getMillis(), delay.getMillis(), TimeUnit.MILLISECONDS);
}

From source file:org.apache.hadoop.metrics2.sink.flume.FlumeTimelineMetricsSink.java

@Override
public void start() {
    LOG.info("Starting Flume Metrics Sink");
    TimelineMetricsCollector timelineMetricsCollector = new TimelineMetricsCollector();
    if (scheduledExecutorService == null || scheduledExecutorService.isShutdown()
            || scheduledExecutorService.isTerminated()) {
        scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    }/*from ww w  .  j a  v a2  s  . com*/
    scheduledExecutorService.scheduleWithFixedDelay(timelineMetricsCollector, 0, pollFrequency,
            TimeUnit.MILLISECONDS);
}

From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.AggregatorConfiguration.java

@Override
public Engine construct() throws IOException {
    NetworkInterface intf = getNetworkInterface();
    DatagramSocket socket;/* ww w  .  j a  va 2  s.co  m*/
    InetSocketAddress address;
    if (endpoint.getAddress().isAnyLocalAddress()) {
        address = new InetSocketAddress(Utils.getAddress(intf, ipv4), endpoint.getPort());
    } else {
        address = endpoint;
    }
    try {
        socket = new DatagramSocket(address);
    } catch (BindException e) {
        BindException bindException = new BindException(String.format("Cannot bind to %s", address));
        bindException.initCause(e);
        throw bindException;
    }
    return new AggregatorEngine(socket, getMac(), Executors.newSingleThreadScheduledExecutor(), getFdFactory());
}

From source file:org.zalando.stups.tokens.AccessTokenRefresher.java

public AccessTokenRefresher(final AccessTokensBuilder configuration) {
    this.configuration = configuration;
    scheduler = Executors.newSingleThreadScheduledExecutor();
}

From source file:org.springframework.cloud.aws.autoconfigure.metrics.BufferingCloudWatchMetricSender.java

public BufferingCloudWatchMetricSender(String namespace, int maxBuffer, long nextRunDelayMillis,
        AmazonCloudWatchAsync amazonCloudWatchAsync) {
    this(namespace, maxBuffer, nextRunDelayMillis, amazonCloudWatchAsync,
            Executors.newSingleThreadScheduledExecutor());
}

From source file:org.dcm4che3.tool.mppsscu.MppsSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from   w w  w  . j a va 2 s  .c  om*/
        CommandLine cl = parseComandLine(args);
        Device device = new Device("mppsscu");
        Connection conn = new Connection();
        device.addConnection(conn);
        ApplicationEntity ae = new ApplicationEntity("MPPSSCU");
        device.addApplicationEntity(ae);
        ae.addConnection(conn);
        final MppsSCU main = new MppsSCU(ae);
        configureMPPS(main, cl);
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(conn, main.ae, cl);
        CLIUtils.configure(conn, cl);
        main.remote.setTlsProtocols(conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(conn.getTlsCipherSuites());
        main.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        main.setAttributes(new Attributes());
        CLIUtils.addAttributes(main.attrs, cl.getOptionValues("s"));
        main.setUIDSuffix(cl.getOptionValue("uid-suffix"));
        List<String> argList = cl.getArgList();
        boolean echo = argList.isEmpty();
        if (!echo) {
            System.out.println(rb.getString("scanning"));
            main.scanFiles(argList, true);
        }
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        device.setExecutor(executorService);
        device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            if (echo)
                main.echo();
            else {
                main.createMpps();
                main.updateMpps();
            }
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("mppsscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("mppsscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:io.fabric8.che.starter.openshift.CheDeploymentConfig.java

private void waitUntilDeploymentConfigIsAvailable(final OpenShiftClient client, String namespace) {
    final BlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(1);

    final Runnable readinessPoller = new Runnable() {
        public void run() {
            try {
                if (isDeploymentAvailable(client, namespace)) {
                    queue.put(true);// ww w  .j a  v a2s .c  o  m
                    return;
                } else {
                    queue.put(false);
                    return;
                }
            } catch (Throwable t) {
                try {
                    if (queue.isEmpty()) {
                        queue.put(false);
                    }
                    return;
                } catch (InterruptedException e) {
                }
            }
        }
    };

    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    ScheduledFuture<?> poller = executor.scheduleWithFixedDelay(readinessPoller, 0, 500, TimeUnit.MILLISECONDS);
    executor.schedule(new Runnable() {

        @Override
        public void run() {
            poller.cancel(true);
        }
    }, Integer.valueOf(startTimeout), TimeUnit.SECONDS);
    try {
        while (!waitUntilReady(queue)) {
        }
    } finally {
        if (!poller.isDone()) {
            poller.cancel(true);
        }
        executor.shutdown();
    }
}