-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadC.java
More file actions
61 lines (49 loc) · 1.51 KB
/
ThreadC.java
File metadata and controls
61 lines (49 loc) · 1.51 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
import java.io.*;
class ThreadC extends Thread
{
PipedOutputStream toA;
PipedInputStream fromA;
PipedInputStream fromB;
ObjectOutputStream writerC;
ThreadC() throws IOException {
toA = new PipedOutputStream();
fromA = new PipedInputStream();
fromB = new PipedInputStream();
}
ThreadC(PipedOutputStream outA,
PipedInputStream inA, PipedInputStream inB,
ObjectOutputStream write) {
toA = outA;
fromA = inA;
fromB = inB;
writerC = write;
}
public void run() {
System.out.println("C- Started");
try {
//OUTGOING
//TC sends objects to TA
Message m = new Message();
m.theMessage = "Hi A!";
String[] arr = {"It's", "C!"};
m.someLines = arr;
m.someNumber = 33;
System.out.println("C- Sending object to A { " + '\n' + m.toString());
writerC = new ObjectOutputStream(toA);//conversion
writerC.writeObject(m);
writerC.flush();
writerC.close();
//INCOMING
//TC receives primitive data from TA
System.out.println("C- Receiving primitive from A: " + fromA.read());
fromA.close();
//TC receives primitive data from TB
System.out.println("C- Receiving primitive from B: " + fromB.read());
fromB.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}