Skip to content

Commit 659a367

Browse files
authored
why do u not rather allow yourselves 2b defrauded?
Now therefore there is utterly a fault among you, because you go to law one with another. Why do you not rather take wrong? why do you not rather allow yourselves to be defrauded? (1Cor 6:7)
1 parent 9a93231 commit 659a367

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
//Now therefore there is utterly a fault among you, because you go to law one with another. Why do you not rather take wrong? why do you not rather allow yourselves to be defrauded? (1Cor 6:7)
3+
4+
package com.javarush.task.task27.task2710;
5+
6+
public class MailServer implements Runnable {
7+
private Mail mail;
8+
9+
public MailServer(Mail mail) {
10+
this.mail = mail;
11+
}
12+
13+
@Override
14+
public void run() {
15+
long beforeTime = System.currentTimeMillis();
16+
17+
synchronized (mail){ //сделайте что-то тут - do something here
18+
while (mail.getText() == null)
19+
try {
20+
mail.wait();
21+
}catch (Exception e) {e.printStackTrace();}
22+
}
23+
String name = Thread.currentThread().getName();
24+
long afterTime = System.currentTimeMillis();
25+
System.out.format("%s MailServer has got: [%s] in %d ms after start", name, mail.getText(), (afterTime - beforeTime));
26+
}
27+
}
28+
/*
29+
Расставьте wait-notify
30+
Расставь wait-notify.
31+
32+
Пример вывода:
33+
Thread-0 MailServer has got: [Person [Thread-1] has written an email 'AAA'] in 1001 ms after start
34+
35+
36+
Требования:
37+
1. Объекты класса MailServer должны работать корректно в многопоточном окружении.
38+
2. Объекты класса Person должны работать корректно в многопоточном окружении.
39+
3. В методе run класса MailServer должен присутствовать synchronized блок, монитор - mail.
40+
4. В методе run класса Person должен присутствовать synchronized блок, монитор - mail.
41+
*/

0 commit comments

Comments
 (0)