List of usage examples for java.util.concurrent Executors newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
From source file:Main.java
public static void main(String[] args) { int NTHREADS = 25; ExecutorService exec = Executors.newFixedThreadPool(NTHREADS); exec.submit(new MailConsumer()); exec.submit(new MailProducer()); System.out.println("inside main"); }
From source file:MainClass.java
public static void main(String[] args) { ExecutorService application = Executors.newFixedThreadPool(2); Buffer sharedLocation = new UnsynchronizedBuffer(); System.out.println("Action\t\tValue\tProduced\tConsumed"); System.out.println("------\t\t-----\t--------\t--------\n"); try {//from w ww .j a v a2 s. com application.execute(new Producer(sharedLocation)); application.execute(new Consumer(sharedLocation)); } catch (Exception exception) { exception.printStackTrace(); } application.shutdown(); // terminate application when threads end }
From source file:Main.java
public static void main(String args[]) throws Exception { ExecutorService es = Executors.newFixedThreadPool(3); Future<Double> f = es.submit(new Avg()); Future<Integer> f2 = es.submit(new Factorial()); System.out.println(f.get());/* w ww.j ava 2 s. c om*/ System.out.println(f2.get()); es.shutdown(); }
From source file:Main.java
public static void main(String args[]) throws Exception { ExecutorService es = Executors.newFixedThreadPool(3); Future<Double> f = es.submit(new Task1()); Future<Integer> f2 = es.submit(new Task2()); System.out.println(f.get());//w w w .ja v a 2 s . c o m System.out.println(f2.get()); es.shutdown(); }
From source file:Main.java
public static void main(String[] args) throws IOException { ExecutorService service = Executors.newFixedThreadPool(4); BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in)); String line;// www . ja va 2 s. c o m while ((line = buffer.readLine()) != null) { service.execute(new Worker(line)); } }
From source file:Main.java
public static void main(String[] args) throws Exception { ExecutorService service = Executors.newFixedThreadPool(5); List<Future<java.lang.String>> futureList = service .invokeAll(Arrays.asList(new Task1<String>(), new Task2<String>())); System.out.println(futureList.get(1).get()); System.out.println(futureList.get(0).get()); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1); List<Particle> allTheParticles = new ArrayList<>(); for (int i = 0; i < 20; i++) { allTheParticles.add(new Particle(i, allTheParticles)); }/* w ww . j a v a2 s. co m*/ while (true) { executor.invokeAll(allTheParticles); executor.invokeAll(allTheParticles); } }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Main task = new Main(); int threads = Runtime.getRuntime().availableProcessors(); ExecutorService pool = Executors.newFixedThreadPool(threads); for (int i = 0; i < threads; i++) { pool.submit(task);/*from w w w. j ava 2 s. c o m*/ } pool.awaitTermination(120, TimeUnit.SECONDS); }
From source file:Main.java
public static void main(String[] args) throws Exception { System.out.println("Thread pool size = " + MAX_THREADS); ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS); Future previousFuture = null; for (int i = 0; i < MAX_THREADS; i++) { JobRunnable job = new JobRunnable(i, previousFuture); previousFuture = executor.submit(job); }// w ww . jav a 2 s . com executor.shutdown(); executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); System.out.println("Program done."); }
From source file:Main.java
public static void main(String[] args) { CyclicBarrier barrier = new CyclicBarrier(2); Receiver receiver = new Receiver(barrier); Sender sender = new Sender(barrier); ExecutorService executor = Executors.newFixedThreadPool(2); executor.submit(receiver);/*w w w .j a v a 2s . c o m*/ executor.submit(sender); }