-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerson.java
More file actions
67 lines (52 loc) · 2.17 KB
/
Person.java
File metadata and controls
67 lines (52 loc) · 2.17 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
61
62
63
64
65
66
67
//But brother goes to law with brother, and that before the unbelievers (1Cor 6:6)
package com.javarush.task.task27.task2710;
public class Person implements Runnable {
private final Mail mail;
public Person(Mail mail) {
this.mail = mail;
}
@Override
public void run() {
String name = Thread.currentThread().getName();
try {
Thread.sleep(1000);
//сделайте что-то тут - do something here
mail.setText("Person [" + name + "] has written an email 'AAA'");
synchronized (mail) { //сделайте что-то тут - do something here
mail.notifyAll();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/*
Расставьте wait-notify
Расставь wait-notify.
Пример вывода:
Thread-0 MailServer has got: [Person [Thread-1] has written an email 'AAA'] in 1001 ms after start
Требования:
1. Объекты класса MailServer должны работать корректно в многопоточном окружении.
2. Объекты класса Person должны работать корректно в многопоточном окружении.
3. В методе run класса MailServer должен присутствовать synchronized блок, монитор - mail.
4. В методе run класса Person должен присутствовать synchronized блок, монитор - mail.
package com.javarush.task.task27.task2710;
public class Person implements Runnable {
private final Mail mail;
public Person(Mail mail) {
this.mail = mail;
}
@Override
public void run() {
String name = Thread.currentThread().getName();
try {
Thread.sleep(1000);
//сделайте что-то тут - do something here
mail.setText("Person [" + name + "] has written an email 'AAA'");
//сделайте что-то тут - do something here
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
*/