Skip to content

Commit 9a93231

Browse files
authored
brother goes to law with brother
But brother goes to law with brother, and that before the unbelievers (1Cor 6:6)
1 parent e0ea73f commit 9a93231

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
//But brother goes to law with brother, and that before the unbelievers (1Cor 6:6)
3+
4+
package com.javarush.task.task27.task2710;
5+
6+
public class Person implements Runnable {
7+
private final Mail mail;
8+
9+
public Person(Mail mail) {
10+
this.mail = mail;
11+
}
12+
13+
@Override
14+
public void run() {
15+
String name = Thread.currentThread().getName();
16+
try {
17+
Thread.sleep(1000);
18+
//сделайте что-то тут - do something here
19+
mail.setText("Person [" + name + "] has written an email 'AAA'");
20+
21+
synchronized (mail) { //сделайте что-то тут - do something here
22+
mail.notifyAll();
23+
}
24+
25+
} catch (InterruptedException e) {
26+
e.printStackTrace();
27+
}
28+
}
29+
}
30+
31+
/*
32+
Расставьте wait-notify
33+
Расставь wait-notify.
34+
35+
Пример вывода:
36+
Thread-0 MailServer has got: [Person [Thread-1] has written an email 'AAA'] in 1001 ms after start
37+
38+
39+
Требования:
40+
1. Объекты класса MailServer должны работать корректно в многопоточном окружении.
41+
2. Объекты класса Person должны работать корректно в многопоточном окружении.
42+
3. В методе run класса MailServer должен присутствовать synchronized блок, монитор - mail.
43+
4. В методе run класса Person должен присутствовать synchronized блок, монитор - mail.
44+
45+
package com.javarush.task.task27.task2710;
46+
47+
public class Person implements Runnable {
48+
private final Mail mail;
49+
50+
public Person(Mail mail) {
51+
this.mail = mail;
52+
}
53+
54+
@Override
55+
public void run() {
56+
String name = Thread.currentThread().getName();
57+
try {
58+
Thread.sleep(1000);
59+
//сделайте что-то тут - do something here
60+
mail.setText("Person [" + name + "] has written an email 'AAA'");
61+
//сделайте что-то тут - do something here
62+
} catch (InterruptedException e) {
63+
e.printStackTrace();
64+
}
65+
}
66+
}
67+
*/

0 commit comments

Comments
 (0)