Advertisement
sergAccount

Untitled

Mar 14th, 2021
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.app22;
  7.  
  8. public class MyPrintTask implements Runnable {
  9.  
  10.     private int m;
  11.     private long etime;
  12.  
  13.     public MyPrintTask(int m) {
  14.         this.m = m;
  15.     }
  16.  
  17.     @Override
  18.     public void run() {
  19.         final long ctime = System.currentTimeMillis();
  20.         try {
  21.             for (int i = m; i >= 0; i--) {
  22.                 //System.out.println(m);
  23.                 System.out.println("MyPrintTask (" + Thread.currentThread().getName() + ")" + i);
  24.                 try {
  25.                     Thread.sleep(2000);
  26.                 } catch (InterruptedException ex) {
  27.                     ex.printStackTrace();
  28.                 }
  29.             }
  30.         } finally {
  31.             etime = System.currentTimeMillis() - ctime;
  32.         }
  33.     }
  34.     //
  35.     public long getExecutionTime() {
  36.         return etime;
  37.     }
  38.     public int getM() {
  39.         return m;
  40.     }
  41.     public void setM(int m) {
  42.         this.m = m;
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement