congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ExecutorService.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.util.concurrent.ExecutorService
constructor

Best Java code snippets using java.util.concurrent.ExecutorService.<init> (Showing top 8 results out of 2,574)

origin: stackoverflow.com

 ThreadPoolExecutor pool = new ThreadPoolExecutor(...);
ExecutorService svc = new ControlledExecutorService(pool);
server.setThreadPool(new org.eclipse.jetty.util.thread.ExecutorThreadPool(svc));
origin: stackoverflow.com

 ExecutorService es = Executors.new.....
es.submit(new Runnable() {
  public void run() {
    // a task you want to pass to another thread
  }
});
origin: stackoverflow.com

 ExecutorService executor = new FixedThreadPool(100); //pool of 100 threads

...

Runnable r = new Runnable() {

  public void run() {
    try {
      System.out.println(cmd);
      Process process = Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
      e.printStackTrace();
    }  
  }
}

executor.submit(r);
origin: stackoverflow.com

 private static final int procs = Runtime.getRuntime().availableProcessors();
private final ExecutorService es = new Executors.newFixedThreadPool(procs);

int tasks = ....
int blockSize = (tasks + procss -1) / procs;
List<Future<Results>> futures = new ArrayList<>();

for(int i = 0; i < procs; i++) {
  int start = i * blockSize;
  int end = Math.min(tasks, (i + 1) * blockSize);
  futures.add(es.submit(new Task(start, end));
}

for(Future<Result> future: futures) {
  Result result = future.get();
  // check/accumulate result.
}
origin: stackoverflow.com

 ExecutorService executorService = new ThreadPoolExecutorService(...);
executorService.submit(new A(200));
executorService.submit(new A(100));
executorService.submit(new A(500));

executorService.shutdown();
executorService.awaitTermination(/* some timeout */);

System.out.println("Main Thread's rest of the code");
origin: stackoverflow.com

 public class ReportThread extends Thread {
 final int delay;
 boolean finished;

 ReportThread() { finished = false; }
 void done() { finished = true; }

 public void run() {
  while (!finished) {    
   Thread.sleep(delay);
   System.out.println("Computing long task..");
  }
 }
}

ReportThread report = new ReportThread(1000);
report.start();
ExecutorService service = new ExecutorService();
Future<T> future = service.submit(new Future<T>(new Callable<T>() {
 public T call() {
  // long task implementation
 })
);
T result = future.get();
report.done();
origin: stackoverflow.com

 public static void main(String[] args) throws InterruptedException {
  ExecutorService service = new TimeoutThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, 
      new LinkedBlockingQueue<Runnable>(), 10, TimeUnit.MINUTES);
  //ExecutorService service = Executors.newFixedThreadPool(1);
  try {
    final AtomicInteger counter = new AtomicInteger();
    for (long i = 0; i < 10000000; i++) {
      service.submit(new Runnable() {
        @Override
        public void run() {
          counter.incrementAndGet();
        }
      });
      if (i % 10000 == 0) {
        System.out.println(i + "/" + counter.get());
        while (i > counter.get()) {
          Thread.sleep(10);
        }
      }
    }
  } finally {
    service.shutdown();
  }
}
origin: stackoverflow.com

ExecutorService timedExecutor = new TimedExecutorService(numThreads, timeout, TimeUnit.SECONDS);
timedExecutor.execute(abcdRunnable);
timedExecutor.execute(xyzwRunnable);
java.util.concurrentExecutorService<init>

Popular methods of ExecutorService

  • submit
    Submits a value-returning task for execution and returns a Future representing the pending results o
  • shutdown
    Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks wil
  • execute
  • shutdownNow
    Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a
  • awaitTermination
    Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or
  • isShutdown
    Returns true if this executor has been shut down.
  • isTerminated
    Returns true if all tasks have completed following shut down. Note that isTerminated is never true
  • invokeAll
    Executes the given tasks, returning a list of Futures holding their status and results when all comp
  • invokeAny
    Executes the given tasks, returning the result of one that has completed successfully (i.e., without

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • findViewById (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • JButton (javax.swing)
  • Github Copilot alternatives
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