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(ThreadFactory threadFactory) 

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.linkedin.pinot.controller.helix.core.relocation.RealtimeSegmentRelocator.java

public RealtimeSegmentRelocator(PinotHelixResourceManager pinotHelixResourceManager, ControllerConf config) {
    _pinotHelixResourceManager = pinotHelixResourceManager;
    _helixManager = pinotHelixResourceManager.getHelixZkManager();
    _helixAdmin = pinotHelixResourceManager.getHelixAdmin();
    _runFrequencySeconds = getRunFrequencySeconds(config.getRealtimeSegmentRelocatorFrequency());

    _executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override/*from   w  w w  .j  a v  a 2s .  c o  m*/
        public Thread newThread(Runnable runnable) {
            Thread thread = new Thread(runnable);
            thread.setName("RealtimeSegmentRelocatorExecutorService");
            return thread;
        }
    });
}

From source file:org.eclipse.che.api.builder.internal.SourcesManagerImpl.java

public SourcesManagerImpl(java.io.File directory) {
    this.directory = directory;
    tasks = new ConcurrentHashMap<>();
    projectKeyHolder = new AtomicReference<>();
    executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
            .setNameFormat(getClass().getSimpleName() + "-FileCleaner-%d").setDaemon(true).build());
    listeners = new CopyOnWriteArraySet<>();
}

From source file:org.hawkular.apm.performance.server.ClientSimulator.java

public void run() {
    Metrics metrics = new Metrics(name);
    ServiceRegistry reg = new DefaultServiceRegistry(systemConfig, metrics);

    List<PathConfiguration> paths = new ArrayList<PathConfiguration>();
    for (PathConfiguration pc : systemConfig.getPaths()) {
        for (int i = 0; i < pc.getWeight(); i++) {
            paths.add(pc);//from   w w w.j a v a2  s  .co m
        }
    }

    // Initialise publisher metrics handler
    TracePublisher publisher = ServiceResolver.getSingletonService(TracePublisher.class);
    if (publisher == null) {
        log.severe("Trace publisher has not been configured correctly");
        return;
    }

    publisher.setMetricHandler(new PublisherMetricHandler<Trace>() {
        @Override
        public void published(String tenantId, List<Trace> items, long metric) {
            metrics.publishTraces(metric);
        }
    });

    Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setDaemon(true);
            return t;
        }
    }).scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            metrics.report();
        }
    }, 1, 1, TimeUnit.SECONDS);

    for (int i = 0; i < requesters; i++) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("THREAD: " + Thread.currentThread() + ": STARTED");

                for (int j = 0; j < invocations; j++) {
                    // Randomly select path
                    int index = (int) (Math.random() * (paths.size() - 1));

                    Service s = reg.getServiceInstance(paths.get(index).getService());

                    Message m = new Message(paths.get(index).getName());

                    s.call(m, null, null);
                }

                System.out.println("THREAD: " + Thread.currentThread() + ": FINISHED: " + new java.util.Date());

                synchronized (this) {
                    try {
                        wait(2000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
}

From source file:org.xdi.oxd.server.license.LicenseService.java

private void schedulePeriodicValidation() {
    final ScheduledExecutorService executorService = Executors
            .newSingleThreadScheduledExecutor(CoreUtils.daemonThreadFactory());
    executorService.scheduleAtFixedRate(new Runnable() {
        @Override/*from www .j  a v  a 2  s  . com*/
        public void run() {
            licenseValid = validate();
        }
    }, 1, 24, TimeUnit.HOURS);
}

From source file:com.twitter.hraven.hadoopJobMonitor.metrics.HadoopJobMonitorMetrics.java

static HadoopJobMonitorMetrics create(Configuration conf) {
    MetricsSystem ms = DefaultMetricsSystem.instance();

    HadoopJobMonitorMetrics metricObject = new HadoopJobMonitorMetrics();
    MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(metricObject);
    final MetricsSource s = sb.build();
    ms.register("HadoopJobMonitorMetrics", "The Metrics of HadoopJobMonitor service", s);

    ScheduledExecutorService heartbeatExecutor = Executors
            .newSingleThreadScheduledExecutor(new SimpleThreadFactory());
    heartbeatExecutor.scheduleAtFixedRate(metricObject.new Heart(), 0, 1, TimeUnit.MINUTES);
    return metricObject;
}

From source file:org.apache.synapse.commons.jmx.ThreadingView.java

public ThreadingView(final String threadNamePrefix) {
    this.threadNamePrefix = threadNamePrefix;
    this.scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        public Thread newThread(Runnable r) {
            return new Thread(r, "Thread-view-" + threadNamePrefix);
        }// w  w  w  .j  a  va 2  s. c  o  m
    });
    initMBean();
}

From source file:com.careerly.common.support.ReloadablePropertySourcesPlaceholderConfigurer.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notEmpty(locations, "properties reload, locations not given");
    // ??/*w w w.j a va2 s  .  co m*/
    for (Resource resource : locations) {
        long modified = resource.lastModified();
        String modifiedTime = new DateTime(modified).toString("yyyy-MM-dd HH:mm:ss");
        logger.info("properties monitor, file: {}, modified: {}", resource.getFile().getPath(), modifiedTime);
        lastModifiedResources.put(resource, modified);
    }
    // ??Constant?
    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        if (beanName.endsWith("Constant")) {
            logger.info("properties monitor, bean: {}", beanName);
            beanNames.add(beanName);
        }
    }
    // ??10??JDK7?nio2 Watch Service
    scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("properties-reload"));
    scheduler.scheduleWithFixedDelay(this, 120L, 10L, TimeUnit.SECONDS);
}

From source file:net.sourceforge.subsonic.service.PodcastService.java

public PodcastService() {
    ThreadFactory threadFactory = new ThreadFactory() {
        public Thread newThread(Runnable r) {
            Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setDaemon(true);//from   www .j  ava2 s. c  o m
            return t;
        }
    };
    refreshExecutor = Executors.newFixedThreadPool(5, threadFactory);
    downloadExecutor = Executors.newFixedThreadPool(3, threadFactory);
    scheduledExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory);
}

From source file:password.pwm.svc.wordlist.AbstractWordlist.java

public void init(final PwmApplication pwmApplication) throws PwmException {
    this.pwmApplication = pwmApplication;
    this.localDB = pwmApplication.getLocalDB();
    if (pwmApplication.getConfig().isDevDebugMode()) {
        debugTrace = true;//ww w . jav a 2  s  .co  m
    }

    executorService = Executors.newSingleThreadScheduledExecutor(JavaHelper
            .makePwmThreadFactory(JavaHelper.makeThreadName(pwmApplication, this.getClass()) + "-", true));
}

From source file:org.apache.pulsar.compaction.CompactionTest.java

@BeforeMethod
@Override/* w  w w . jav a 2 s .  co  m*/
public void setup() throws Exception {
    super.internalSetup();

    admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1:" + BROKER_WEBSERVICE_PORT));
    admin.tenants().createTenant("my-property",
            new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("my-property/use/my-ns");

    compactionScheduler = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("compaction-%d").setDaemon(true).build());
    bk = pulsar.getBookKeeperClientFactory().create(this.conf, null);
}