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.app4;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Admin
- */
- public class Main {
- public static void main(String[] args) {
- //
- int[] array = {1, 2, 3, 4};
- AvgTask a1 = new AvgTask(array);
- AvgTask a2 = new AvgTask(array);
- // массив потоков
- Thread[] arr = {new Thread(a1), new Thread(a2)};
- // запускаем все потоки на выполнение
- for (int i = 0; i < arr.length; i++) {
- arr[i].start();
- }
- // ожидаем завершения выполнения каждого из потоков
- for (int i = 0; i < arr.length; i++) {
- try {
- arr[i].join();
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- }
- // поучаем рез-ты всех задач
- System.out.println("a1.getResult()=" + a1.getResult());
- System.out.println("a2.getResult()=" + a2.getResult());
- double total = a1.getResult() * a2.getResult();
- System.out.println("total=" + total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement