-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadB.java
More file actions
54 lines (44 loc) · 1.28 KB
/
ThreadB.java
File metadata and controls
54 lines (44 loc) · 1.28 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
import java.io.*;
class ThreadB extends Thread
{
PipedOutputStream toA;
PipedOutputStream toC;
ObjectOutputStream writerA;
ThreadB() throws IOException {
toA = new PipedOutputStream();
toC = new PipedOutputStream();
}
ThreadB(PipedOutputStream outA, PipedOutputStream outC,
ObjectOutputStream write) {
toA = outA;
toC = outC;
writerA = write;
}
public void run() {
System.out.println("B- Started");
try {
//OUTGOING
//TB will send objects to TA
Message m = new Message();
m.theMessage = "Hi A!";
String[] arr = {"It's", "B!"};
m.someLines = arr;
m.someNumber = 22;
System.out.println("B- Sending object to A { " + '\n' + m.toString());
writerA = new ObjectOutputStream(toA);//conversion
writerA.writeObject(m);
writerA.flush();
writerA.close();
//TB will send primitive data to TC
System.out.println("B- Sending primitive to C: " + 2);
toC.write(2);
toC.flush();
toC.close();
//INCOMING
////
}
catch (Exception e) {
e.printStackTrace();
}
}
}