Advertisement
sergAccount

Untitled

Jan 23rd, 2021
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 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.app2;
  7.  
  8. /**
  9.  *
  10.  * @author Admin
  11.  */
  12. public class MyPrintTask implements Runnable{
  13.  
  14.     @Override
  15.     public void run() {
  16.         String message = "Hello Java!";
  17.         //for(;;){
  18.         while(true){
  19.             try{
  20.                 Thread.sleep(5000);// 5000 ms = 5 s
  21.             }catch(Exception ex){
  22.              ex.printStackTrace();
  23.             }
  24.             // Thread.currentThread().getName() - имя потока выполнения
  25.             System.out.println(Thread.currentThread().getName() + ": " + message);
  26.         }
  27.     }    
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement