Tabnine Logo
Executors.newScheduledThreadPool
Code IndexAdd Tabnine to your IDE (free)

How to use
newScheduledThreadPool
method
in
java.util.concurrent.Executors

Best Java code snippets using java.util.concurrent.Executors.newScheduledThreadPool (Showing top 20 results out of 9,621)

Refine searchRefine arrow

  • ScheduledExecutorService.scheduleAtFixedRate
  • ScheduledExecutorService.schedule
  • PrintStream.println
  • Executors.newCachedThreadPool
  • Threads.daemonThreadsNamed
origin: code4craft/webmagic

private void initFlushThread() {
  flushThreadPool = Executors.newScheduledThreadPool(1);
  flushThreadPool.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      flush();
    }
  }, 10, 10, TimeUnit.SECONDS);
}
origin: oracle/helidon

private synchronized void planNextTry(long afterMillis) {
  if (scheduledExecutorService == null) {
    scheduledExecutorService = Executors.newScheduledThreadPool(1);
  }
  scheduledExecutorService.schedule(this::tryPublish, afterMillis, TimeUnit.MILLISECONDS);
}
origin: stackoverflow.com

 Runnable helloRunnable = new Runnable() {
  public void run() {
    System.out.println("Hello world");
  }
};

ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(helloRunnable, 0, 3, TimeUnit.SECONDS);
origin: linkedin/parseq

 public static void main(String[] args) throws InterruptedException {
  final long viewerId = 0;

  final Set<Long> unclassified = new HashSet<Long>();
  for (long i = 0; i < 20; i++) {
   unclassified.add(i);
  }

  final ScheduledExecutorService serviceScheduler = Executors.newSingleThreadScheduledExecutor();
  final Client restLiClient = new ClientImpl(serviceScheduler);

  final int numCores = Runtime.getRuntime().availableProcessors();
  final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(numCores + 1);
  final Engine engine = new EngineBuilder().setTaskExecutor(scheduler).setTimerScheduler(scheduler).build();

  final ClassifierPlanFactory classifier = new ClassifierPlanFactory(restLiClient);
  try {
   final Task<Map<Long, Classification>> classifications = classifier.classify(viewerId, unclassified);
   engine.run(classifications);
   classifications.await();
   System.out.println(classifications.get());

   ExampleUtil.printTracingResults(classifications);
  } finally {
   serviceScheduler.shutdownNow();
   engine.shutdown();
   scheduler.shutdownNow();
  }
 }
}
origin: LeonardoZ/java-concurrency-patterns

public static void usingScheduledThreadPool() {
  System.out.println("=== ScheduledThreadPool ===");
  ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(4);
  scheduledThreadPool.scheduleAtFixedRate(
      () -> System.out.println("Print every 2s"), 0, 2, TimeUnit.SECONDS);
  scheduledThreadPool.scheduleWithFixedDelay(
      () -> System.out.println("Print every 2s delay"), 0, 2, TimeUnit.SECONDS);
  try {
    scheduledThreadPool.awaitTermination(6, TimeUnit.SECONDS);
    scheduledThreadPool.shutdown();
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
}
origin: biezhi/learn-java8

private static void test1() throws InterruptedException {
  ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
  Runnable           task   = () -> System.out.println("Scheduling: " + System.nanoTime());
  int                delay  = 3;
  ScheduledFuture<?> future = executor.schedule(task, delay, TimeUnit.SECONDS);
  TimeUnit.MILLISECONDS.sleep(1337);
  long remainingDelay = future.getDelay(TimeUnit.MILLISECONDS);
  System.out.printf("Remaining Delay: %sms\n", remainingDelay);
}
origin: stackoverflow.com

System.out.println("sampling started");
CLASS=className;
METHOD=method;
EXECUTOR = Executors.newScheduledThreadPool(1);
if(t==null) System.out.println("method not seen");
else printCallTree(t, 0, 100);
 sb.append(chPercent).append("% (").append(cht.cpu*percent/num)
  .append("% cpu) ").append(ch.getKey()).append(" ");
 System.out.println(sb.toString());
 printCallTree(cht, ind+2, chPercent);
origin: stackoverflow.com

import static java.util.concurrent.TimeUnit.*;
class BeeperControl {
 private final ScheduledExecutorService scheduler =
   Executors.newScheduledThreadPool(1);
 public void beepForAnHour() {
   final Runnable beeper = new Runnable() {
       public void run() { System.out.println("beep"); }
     };
   final ScheduledFuture<?> beeperHandle =
     scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
   scheduler.schedule(new Runnable() {
       public void run() { beeperHandle.cancel(true); }
     }, 60 * 60, SECONDS);
 }
}
origin: prestodb/presto

public TestScanFilterAndProjectOperator()
{
  executor = newCachedThreadPool(daemonThreadsNamed("test-executor-%s"));
  scheduledExecutor = newScheduledThreadPool(2, daemonThreadsNamed("test-scheduledExecutor-%s"));
}
origin: apache/hive

cacheUpdateMaster = Executors.newScheduledThreadPool(1, new ThreadFactory() {
 @Override
 public Thread newThread(Runnable r) {
 cacheUpdateMaster.scheduleAtFixedRate(new CacheUpdateMasterWork(conf, shouldRunPrewarm), 0,
   cacheRefreshPeriodMS, TimeUnit.MILLISECONDS);
cacheUpdateMaster.schedule(new CacheUpdateMasterWork(conf, shouldRunPrewarm), 0, TimeUnit.MILLISECONDS);
origin: prestodb/presto

@Provides
@Singleton
@ForExchange
public static ScheduledExecutorService createExchangeExecutor(ExchangeClientConfig config)
{
  return newScheduledThreadPool(config.getClientThreads(), daemonThreadsNamed("exchange-client-%s"));
}
origin: stackoverflow.com

 public static void main(String[] args) throws InterruptedException {
  ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
  Runnable r = new Runnable() {
    @Override
    public void run() {
      System.out.println("Hello");
    }
  };
  ScheduledFuture<?> scheduledFuture =
    scheduledExecutorService.scheduleAtFixedRate(r, 1L, 1L, TimeUnit.SECONDS);
  Thread.sleep(5000L);
  scheduledFuture.cancel(false);
}
origin: linkedin/parseq

final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(numCores + 1);
final Engine engine = new EngineBuilder()
  .setTaskExecutor(scheduler)
 engine.run(classifications);
 classifications.await();
 System.out.println(classifications.get());
origin: stackoverflow.com

ScheduledExecutorService scheduler = Executors
     .newScheduledThreadPool(1);
 ScheduledFuture<String> future = scheduler.schedule(
     new ScheduledPrinter(), 10, TimeUnit.SECONDS);
 System.out.println(future.get());
origin: biezhi/learn-java8

private static void test3() {
  ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
  Runnable task = () -> {
    try {
      TimeUnit.SECONDS.sleep(2);
      System.out.println("Scheduling: " + System.nanoTime());
    } catch (InterruptedException e) {
      System.err.println("task interrupted");
    }
  };
  executor.scheduleWithFixedDelay(task, 0, 1, TimeUnit.SECONDS);
}
origin: prestodb/presto

@BeforeClass
public void setUp()
{
  executor = newCachedThreadPool(daemonThreadsNamed("test-executor-%s"));
  scheduledExecutor = newScheduledThreadPool(2, daemonThreadsNamed("test-scheduledExecutor-%s"));
}
origin: pinterest/secor

private static void loop(ProgressMonitor progressMonitor, long interval) {
final ProgressMonitor monitor = progressMonitor;
Runnable runner = new Runnable() {
  public void run() {
    try {
    monitor.exportStats();
    } catch (Throwable t) {
    LOG.error("Progress monitor failed", t);
    }
  }
  };
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(runner, 0, interval, TimeUnit.SECONDS);
}
origin: normanmaurer/netty-in-action

/**
 * Listing 7.2 Scheduling a task with a ScheduledExecutorService
 * */
public static void schedule() {
  ScheduledExecutorService executor =
      Executors.newScheduledThreadPool(10);
  ScheduledFuture<?> future = executor.schedule(
    new Runnable() {
    @Override
    public void run() {
      System.out.println("Now it is 60 seconds later");
    }
  }, 60, TimeUnit.SECONDS);
  //...
  executor.shutdown();
}
origin: prestodb/presto

@BeforeClass
public void setUp()
{
  stateNotificationExecutor = newScheduledThreadPool(5, daemonThreadsNamed("test-%s"));
}
origin: biezhi/learn-java8

private static void test2() {
  ScheduledExecutorService executor     = Executors.newScheduledThreadPool(1);
  Runnable                 task         = () -> System.out.println("Scheduling: " + System.nanoTime());
  int                      initialDelay = 0;
  int                      period       = 1;
  executor.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
}
java.util.concurrentExecutorsnewScheduledThreadPool

Javadoc

Creates a thread pool that can schedule commands to run after a given delay, or to execute periodically.

Popular methods of Executors

  • newFixedThreadPool
    Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue,
  • newSingleThreadExecutor
    Creates an Executor that uses a single worker thread operating off an unbounded queue, and uses the
  • newCachedThreadPool
    Creates a thread pool that creates new threads as needed, but will reuse previously constructed thre
  • newSingleThreadScheduledExecutor
    Creates a single-threaded executor that can schedule commands to run after a given delay, or to exec
  • defaultThreadFactory
    Returns a default thread factory used to create new threads. This factory creates all new threads us
  • callable
    Returns a Callable object that, when called, runs the given privileged exception action and returns
  • unconfigurableScheduledExecutorService
    Returns an object that delegates all defined ScheduledExecutorService methods to the given executor,
  • unconfigurableExecutorService
    Returns an object that delegates all defined ExecutorService methods to the given executor, but not
  • newWorkStealingPool
    Creates a thread pool that maintains enough threads to support the given parallelism level, and may
  • privilegedThreadFactory
    Legacy security code; do not use.
  • privilegedCallable
    Legacy security code; do not use.
  • privilegedCallableUsingCurrentClassLoader
    Legacy security code; do not use.
  • privilegedCallable,
  • privilegedCallableUsingCurrentClassLoader

Popular in Java

  • Making http post requests using okhttp
  • getExternalFilesDir (Context)
  • onRequestPermissionsResult (Fragment)
  • addToBackStack (FragmentTransaction)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • JFrame (javax.swing)
  • JPanel (javax.swing)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • 21 Best Atom Packages for 2021
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now