-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadA.java
More file actions
57 lines (45 loc) · 1.4 KB
/
ThreadA.java
File metadata and controls
57 lines (45 loc) · 1.4 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
import java.io.*;
class ThreadA extends Thread
{
PipedOutputStream toC;
PipedInputStream fromB;
PipedInputStream fromC;
ObjectInputStream readerA;
ThreadA() throws IOException
{
toC = new PipedOutputStream();
fromB = new PipedInputStream();
fromC = new PipedInputStream();
}
ThreadA(PipedOutputStream outC,
PipedInputStream inB, PipedInputStream inC,
ObjectInputStream read) {
toC = outC;
fromB = inB;
fromC = inC;
readerA = read;
}
public void run() {
System.out.println("A- Started");
try {
//OUTGOING
//TA sends primitive data to TC
System.out.println("A- Sending primitive to C: " + 1);
toC.write(1);
toC.flush();
toC.close();
//INCOMING
//TA receives objects from TB
readerA = new ObjectInputStream(fromB);//conversion
System.out.println("A- Receiving object from B { " + '\n' + readerA.readObject().toString());
readerA.close();
//TA receives objects from TC
readerA = new ObjectInputStream(fromC);//conversion
System.out.println("A- Receiving object from C { " + '\n' + readerA.readObject().toString());
readerA.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}