Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.mycompany.app8_dz;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import java.util.concurrent.Future;
- /**
- *
- * @author Admin
- */
- public class Main2 {
- //
- public static void main(String[] args) {
- //создаем пул потоков
- ExecutorService service = Executors.newFixedThreadPool(5);
- //
- int[] array1 = {6, 12, 48, 32};
- int[] array2 = {6, 12, 48, 32};
- AvgTask avg1 = new AvgTask(array1);
- AvgTask avg2 = new AvgTask(array2);
- // создаем коллекцию задач
- ArrayList<AvgTask> list = new ArrayList<>();
- list.add(avg1);
- list.add(avg2);
- try{
- double total = 1;
- // invokeAll - для запуска задач с помощью пула потока (ExecutorService)
- List<Future<Double>> fList = service.invokeAll(list);
- for(Future<Double> f: fList){
- Double value = f.get();
- System.out.println("AvgTask.value=" + value);
- total *= value;
- }
- System.out.println("total=" + total);
- }catch(Exception exc){
- exc.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement