Skip to content

Commit 127eb6f

Browse files
authored
put away from among yourselves that wicked person
But them that are outside God judges. Therefore put away from among yourselves that wicked person. (1Cor 5:13)
1 parent 913a5d6 commit 127eb6f

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
//But them that are outside God judges. Therefore put away from among yourselves that wicked person. (1Cor 5:13)
3+
4+
package com.javarush.task.task27.task2711;
5+
6+
import java.util.concurrent.CountDownLatch;
7+
8+
/*
9+
CountDownLatch
10+
*/
11+
public class Solution {
12+
13+
private volatile boolean isWaitingForValue = true;
14+
15+
CountDownLatch latch = new CountDownLatch(1);
16+
17+
public void someMethod() throws InterruptedException {
18+
latch.await();
19+
retrieveValue();
20+
latch.countDown();
21+
}
22+
23+
void retrieveValue() {
24+
System.out.println("Value retrieved.");
25+
}
26+
27+
public static void main(String[] args) {
28+
29+
}
30+
}
31+
/*
32+
CountDownLatch
33+
Дана стандартная реализация методологии wait-notify.
34+
Почитай про CountDownLatch и перепиши тело метода someMethod используя поле latch.
35+
Весь лишний код удали из класса.
36+
37+
38+
Требования:
39+
1. Из класса Solution должно быть удалено поле lock.
40+
2. Из метода someMethod должен быть удален synchronized блок.
41+
3. В методе someMethod должен быть вызван метод await без параметров у объекта сохраненного в поле latch.
42+
4. В методе someMethod должен быть вызван метод retrieveValue.
43+
5. В методе someMethod должен быть вызван метод countDown у объекта сохраненного в поле latch.
44+
45+
package com.javarush.task.task27.task2711;
46+
47+
import java.util.concurrent.CountDownLatch;
48+
49+
*
50+
CountDownLatch
51+
*
52+
public class Solution {
53+
private final Object lock = new Object();
54+
private volatile boolean isWaitingForValue = true;
55+
56+
CountDownLatch latch = new CountDownLatch(1);
57+
58+
public void someMethod() throws InterruptedException {
59+
synchronized (lock) {
60+
while (isWaitingForValue) {
61+
lock.wait();
62+
}
63+
64+
retrieveValue();
65+
66+
isWaitingForValue = false;
67+
lock.notify();
68+
}
69+
}
70+
71+
void retrieveValue() {
72+
System.out.println("Value retrieved.");
73+
}
74+
75+
public static void main(String[] args) {
76+
77+
}
78+
}
79+
*/

0 commit comments

Comments
 (0)