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

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

Best Java code snippets using java.util.concurrent.Executors.newWorkStealingPool (Showing top 20 results out of 315)

origin: oracle/opengrok

/**
 * Initializes suggester data for specified indexes. The data is initialized asynchronously.
 * @param luceneIndexes paths to Lucene indexes and name with which the index should be associated
 */
public void init(final Collection<NamedIndexDir> luceneIndexes) {
  if (luceneIndexes == null || luceneIndexes.isEmpty()) {
    logger.log(Level.INFO, "No index directories found, exiting...");
    return;
  }
  if (!projectsEnabled && luceneIndexes.size() > 1) {
    throw new IllegalArgumentException("Projects are not enabled and multiple Lucene indexes were passed");
  }
  synchronized (lock) {
    logger.log(Level.INFO, "Initializing suggester");
    ExecutorService executor = Executors.newWorkStealingPool(rebuildParallelismLevel);
    for (NamedIndexDir indexDir : luceneIndexes) {
      submitInitIfIndexExists(executor, indexDir);
    }
    shutdownAndAwaitTermination(executor, "Suggester successfully initialized");
  }
}
origin: oracle/opengrok

/**
 * Rebuilds the data structures for specified indexes.
 * @param indexDirs paths to lucene indexes and name with which the index should be associated
 */
public void rebuild(final Collection<NamedIndexDir> indexDirs) {
  if (indexDirs == null || indexDirs.isEmpty()) {
    logger.log(Level.INFO, "Not rebuilding suggester data because no index directories were specified");
    return;
  }
  synchronized (lock) {
    logger.log(Level.INFO, "Rebuilding the following suggesters: {0}", indexDirs);
    ExecutorService executor = Executors.newWorkStealingPool(rebuildParallelismLevel);
    for (NamedIndexDir indexDir : indexDirs) {
      SuggesterProjectData data = this.projectData.get(indexDir.name);
      if (data != null) {
        executor.submit(getRebuildRunnable(data));
      } else {
        submitInitIfIndexExists(executor, indexDir);
      }
    }
    shutdownAndAwaitTermination(executor, "Suggesters for " + indexDirs + " were successfully rebuilt");
  }
}
origin: reactor/reactor-core

@Test
public void forkJoinPoolWorkQueueRejectsSubscribers() {
  ExecutorService executorService = Executors.newWorkStealingPool(2);
  WorkQueueProcessor<String> bc = WorkQueueProcessor.<String>builder().executor(executorService).bufferSize(16).build();
  CountDownLatch latch = new CountDownLatch(2);
  TestWorkQueueSubscriber spec1 = new TestWorkQueueSubscriber(latch, "spec1");
  TestWorkQueueSubscriber spec2 = new TestWorkQueueSubscriber(latch, "spec2");
  TestWorkQueueSubscriber spec3 = new TestWorkQueueSubscriber(latch, "spec3");
  bc.subscribe(spec1);
  bc.subscribe(spec2);
  bc.subscribe(spec3);
  bc.onNext("foo");
  bc.onComplete();
  assertThat(spec1.error, is(nullValue()));
  assertThat(spec2.error, is(nullValue()));
  assertThat(spec3.error, is(notNullValue()));
  assertThat(spec3.error.getMessage(),
      is("The executor service could not accommodate another subscriber, detected limit 2"));
  try {
    latch.await(1, TimeUnit.SECONDS);
  }
  catch (InterruptedException e1) {
    fail(e1.toString());
  }
}
origin: reactor/reactor-core

ExecutorService executorService4 = Executors.newFixedThreadPool(2);
ScheduledExecutorService executorService5 = Executors.newScheduledThreadPool(3);
ExecutorService executorService6 = Executors.newWorkStealingPool(4);
ExecutorService executorService7 =
    Executors.unconfigurableExecutorService(executorService4);
origin: biezhi/learn-java8

private static void test4() throws InterruptedException {
  ExecutorService executor = Executors.newWorkStealingPool();
  List<Callable<String>> callables = Arrays.asList(
      () -> "task1",
      () -> "task2",
      () -> "task3");
  executor.invokeAll(callables)
      .stream()
      .map(future -> {
        try {
          return future.get();
        } catch (Exception e) {
          throw new IllegalStateException(e);
        }
      })
      .forEach(System.out::println);
  executor.shutdown();
}
origin: biezhi/learn-java8

private static void test5() throws InterruptedException, ExecutionException {
  ExecutorService executor = Executors.newWorkStealingPool();
  List<Callable<String>> callables = Arrays.asList(
      callable("task1", 2),
      callable("task2", 1),
      callable("task3", 3));
  String result = executor.invokeAny(callables);
  System.out.println(result);
  executor.shutdown();
}
origin: stackoverflow.com

 final ExecutorService service = Executors.newWorkStealingPool();
for (final Object object : objectsToProcess) {
  service.submit(() -> {
      Go to database retrieve data.
      process
      save data
    }
  });
}
origin: stackoverflow.com

 @Configuration
@EnableAsync
public class AsyncConfig extends AsyncConfigurerSupport {
  @Override
  public Executor getAsyncExecutor() {
    return Executors.newWorkStealingPool(); //will use as many threads as your processor has
  }
}
origin: stackoverflow.com

 tp = Executors.newWorkStealingPool(512); // to create up to 512 Threads
//todo the creation loop...
future = tp.submit(()->{/* your port scan */ return true;});
//todo the waiting processing
future.cancel(true);// to cancel your future
origin: oembedler/spring-graphql-common

public GraphQLQueryExecutor forkJoinExecutorService() {
  this.executorService = Executors.newWorkStealingPool();
  return this;
}
origin: org.apache.james/james-server-testing

@Override
public void beforeEach(ExtensionContext context) throws Exception {
  executorService = Executors.newWorkStealingPool();
}
origin: org.kevoree.mwg/core

@Override
public void start() {
  if (_workers == -1) {
    this.service = Executors.newCachedThreadPool();
  } else {
    this.service = Executors.newWorkStealingPool(_workers);
  }
}
origin: liuyuyu/dictator

  @Bean
  public ExecutorService executorService(){
    return Executors.newWorkStealingPool();
  }
}
origin: stackoverflow.com

 List<String> hosts = fetchTargetHosts();

int concurrentHosts = 10;
int concurrentConnections = 100;
ExecutorService hostEs=Executors.newWorkStealingPool(concurrentHosts);
ExecutorService connEs=Executors.newWorkStealingPool(concurrentConnections);

FileDownloader fileDownloader = new FileDownloader();
for(String host: hosts) hostEs.execute(()-> {
  for(String target: new HostDownloader(host).get())
    connEs.execute(()->fileDownloader.accept(target));
});
origin: BruceEckel/OnJava8-Examples

 public static void main(String[] args)
  throws InterruptedException {
  System.out.println(
   Runtime.getRuntime().availableProcessors());
  ExecutorService exec =
   Executors.newWorkStealingPool();
  IntStream.range(0, 10)
   .mapToObj(n -> new ShowThread())
   .forEach(exec::execute);
  exec.awaitTermination(1, TimeUnit.SECONDS);
 }
}
origin: douglascraigschmidt/LiveLessons

/**
 * Constructor initializes the fields.
 */
public SearchStreamGang(List<String> phrasesToFind,
            List<List<CharSequence>> listOfListOfInputToSearch) {
  // Store the phrases to search for.
  mPhrasesToFind = phrasesToFind;
  // Create an Iterator for the array of Strings to search.
  mInputIterator = listOfListOfInputToSearch.iterator();
  // Initialize the Executor with a ForkJoinPool.
  setExecutor(Executors.newWorkStealingPool());
}
origin: stackoverflow.com

 int processorCount = Runtime.getRuntime().availableProcessors();

ExecutorService executor1 = Executors.newFixedThreadPool(processorCount);
ExecutorService executor2 =  
              Executors.newScheduledThreadPool(processorCount);
ExecutorService executor3 = Executors.newWorkStealingPool(); // java-8 API
ForkJoinPool forkJoinPool = new ForkJoinPool(processorCount);
origin: dunwu/javacore

private static void test5() throws InterruptedException, ExecutionException {
  ExecutorService executor = Executors.newWorkStealingPool();
  List<Callable<String>> callables = Arrays.asList(
    callable("task1", 2),
    callable("task2", 1),
    callable("task3", 3));
  String result = executor.invokeAny(callables);
  System.out.println(result);
  executor.shutdown();
}
origin: martinpaljak/apdu4j

public void start(InetSocketAddress address) throws IOException {
  server = HttpServer.create(address, Integer.parseInt(System.getProperty(BACKLOG, "10")));
  // threadpool!
  server.setExecutor(Executors.newWorkStealingPool(Integer.parseInt(System.getProperty(HTTPPOOL, "10"))));
  // Only two handlers.
  server.createContext("/", new MsgHandler());
  server.createContext("/status", new StatusHandler());
  logger.info("Server started on {} ", server.getAddress());
  // Starts in separate thread.
  server.start();
}
origin: com.github.martinpaljak/apdu4j

public void start(InetSocketAddress address) throws IOException {
  server = HttpServer.create(address, Integer.parseInt(System.getProperty(BACKLOG, "10")));
  // threadpool!
  server.setExecutor(Executors.newWorkStealingPool(Integer.parseInt(System.getProperty(HTTPPOOL, "10"))));
  // Only two handlers.
  server.createContext("/", new MsgHandler());
  server.createContext("/status", new StatusHandler());
  logger.info("Server started on {} ", server.getAddress());
  // Starts in separate thread.
  server.start();
}
java.util.concurrentExecutorsnewWorkStealingPool

Javadoc

Creates a work-stealing thread pool using all Runtime#availableProcessorsas its target parallelism level.

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
  • newScheduledThreadPool
    Creates a thread pool that can schedule commands to run after a given delay, or to execute periodica
  • 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
  • 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

  • Creating JSON documents from java classes using gson
  • getSharedPreferences (Context)
  • requestLocationUpdates (LocationManager)
  • runOnUiThread (Activity)
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • JFrame (javax.swing)
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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