Repository navigation
Expand file tree
/
Copy pathSolution.java
More file actions
60 lines (46 loc) · 2.15 KB
/
Copy pathSolution.java
File metadata and controls
60 lines (46 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//For I determined not to know anything among you, except Jesus Christ, and him crucified. (1Cor 2:2)
/*
Первый закон Финэйгла: если эксперимент удался, что-то здесь не так...
*/
public class Solution {
public static class YieldRunnable implements Runnable {
private int index;
public YieldRunnable(int index) {
this.index = index;
}
public void run() {
System.out.println("begin-" + index);
Thread.yield();
System.out.println("end-" + index);
}
}
public static void main(String[] args) {
}
}
/*
Первый закон Финэйгла: если эксперимент удался, что-то здесь не так...
Обеспечь переуступку кванта времени (переход хода для текущей нити) для последовательных выводов текста в консоль.
Требования:
1. Класс Solution должен содержать вложенный класс YieldRunnable, который реализует интерфейс Runnable.
2. Класс YieldRunnable должен иметь поле с индексом, которое инициализируется через конструктор.
3. Метод run() должен выводить в консоль сообщения с текущим индексом о начале и конце работы метода.
4. В правильном месте должен быть вызван Thread.yield.
package com.javarush.task.task25.task2514;
*
Первый закон Финэйгла: если эксперимент удался, что-то здесь не так...
*
public class Solution {
public static class YieldRunnable implements Runnable {
private int index;
public YieldRunnable(int index) {
this.index = index;
}
public void run() {
System.out.println("begin-" + index);
System.out.println("end-" + index);
}
}
public static void main(String[] args) {
}
}
*/