Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level16.lesson13.home01;
- /* Thread.currentThread - всегда возвращает текущую нить
- 1. В методе printMsg присвой переменной t текущую нить.
- 2. В методе printMsg после всех действий поставь задержку в 1 миллисекунду.
- */
- public class Solution {
- static int count = 5;
- public static void main(String[] args) {
- NameOfDefferentThreads tt = new NameOfDefferentThreads();
- tt.start();
- for (int i = 0; i < count; i++) {
- tt.printMsg();
- }
- }
- public static class NameOfDefferentThreads extends Thread {
- public void run() {
- for (int i = 0; i < count; i++) {
- printMsg();
- }
- }
- public void printMsg() {
- try {
- Thread t = Thread.currentThread();//присвой переменной t текущую нить
- String name = t.getName();
- System.out.println("name=" + name);
- sleep(1); }
- catch (InterruptedException e) {}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement