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.app22;
- public class Main {
- public static void main(String[] args) {
- // MyPrintTask
- int n = 2;
- Thread[] array = new Thread[n];
- MyPrintTask[] tasks = new MyPrintTask[n];
- // создаем задачу, создаем поток и запускаем на выполнение
- for (int i = 0; i < n; i++) {
- int m = 3;
- tasks[i] = new MyPrintTask(m);
- array[i] = new Thread(tasks[i]);
- array[i].start();
- }
- // ждем выполнения всех задач (join или isAlive класс isAlive())
- for (int i = 0; i < array.length; i++) {
- try{
- array[i].join();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- // fori
- for (int i = 0; i < tasks.length; i++) {
- System.out.println("tasks[i].totalTime=" + tasks[i].getExecutionTime());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement