//A woman, when she gives birth, has sorrow, because her time has come. But when she has delivered the child, she doesn't remember the anguish any more, for the joy that a human being is born into the world. (John 16:21) package com.javarush.task.task16.task1621; /* Thread.currentThread - вÑегда возвÑаÑÐ°ÐµÑ ÑекÑÑÑÑ Ð½Ð¸ÑÑ */ public class Solution { static int count = 5; public static void main(String[] args) { NameOfDifferentThreads tt = new NameOfDifferentThreads(); tt.start(); for (int i = 0; i < count; i++) { tt.printMsg(); } } public static class NameOfDifferentThreads extends Thread { public void run() { for (int i = 0; i < count; i++) { printMsg(); } } public void printMsg() { Thread t = Thread.currentThread();//пÑиÑвой пеÑеменной t ÑекÑÑÑÑ Ð½Ð¸ÑÑ String name = t.getName(); System.out.println("name=" + name); try{//add sleep here - Ð´Ð¾Ð±Ð°Ð²Ñ sleep ÑÑÑ Thread.sleep(1); }catch (Exception e) {e.printStackTrace();} } } } /* Thread.currentThread - вÑегда возвÑаÑÐ°ÐµÑ ÑекÑÑÑÑ Ð½Ð¸ÑÑ 1. РмеÑоде printMsg пÑиÑвой пеÑеменной t ÑекÑÑÑÑ Ð½Ð¸ÑÑ. 2. РмеÑоде printMsg поÑле вÑÐµÑ Ð´ÐµÐ¹ÑÑвий поÑÑÐ°Ð²Ñ Ð·Ð°Ð´ÐµÑÐ¶ÐºÑ Ð² 1 миллиÑекÑндÑ. ТÑебованиÑ: 1.âÐеÑод printMsg должен полÑÑаÑÑ ÑекÑÑÑÑ Ð½Ð¸ÑÑ Ñ Ð¿Ð¾Ð¼Ð¾ÑÑÑ Thread.currentThread. 2.âÐеÑод printMsg должен должен ÑÑÑплÑÑÑ Ð½Ð¸ÑÑ Ð½Ð° 1 миллиÑекÑндÑ. 3.âÐеÑод printMsg должен вÑзÑваÑÑ Ð¼ÐµÑод getName Ñ ÑекÑÑей ниÑи. 4.âÐеÑод main должен вÑзваÑÑ Ð¼ÐµÑод printMsg Ñ Ð¾Ð±ÑекÑа Ñипа NameOfDifferentThreads 5 Ñаз. 5.âÐеÑод run должен вÑзваÑÑ Ð¼ÐµÑод printMsg 5 Ñаз. 6.âÐеÑод printMsg Ñ Ð¾Ð±ÑекÑа Ñипа NameOfDifferentThreads ÑÑммаÑно должен бÑÑÑ Ð²Ñзван 10 Ñаз. package com.javarush.task.task16.task1621; * Thread.currentThread - вÑегда возвÑаÑÐ°ÐµÑ ÑекÑÑÑÑ Ð½Ð¸ÑÑ * public class Solution { static int count = 5; public static void main(String[] args) { NameOfDifferentThreads tt = new NameOfDifferentThreads(); tt.start(); for (int i = 0; i < count; i++) { tt.printMsg(); } } public static class NameOfDifferentThreads extends Thread { public void run() { for (int i = 0; i < count; i++) { printMsg(); } } public void printMsg() { Thread t = null;//пÑиÑвой пеÑеменной t ÑекÑÑÑÑ Ð½Ð¸ÑÑ String name = t.getName(); System.out.println("name=" + name); //add sleep here - Ð´Ð¾Ð±Ð°Ð²Ñ sleep ÑÑÑ } } } */