-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobServerThreadSon.java
More file actions
54 lines (50 loc) · 1.37 KB
/
JobServerThreadSon.java
File metadata and controls
54 lines (50 loc) · 1.37 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
package map_reduce_demo;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.concurrent.LinkedBlockingQueue;
public class JobServerThreadSon extends Thread{
JobClientState jcs;
LinkedBlockingQueue<Job> jobqueue;
WorkState ws;
public JobServerThreadSon(JobClientState Jcs,LinkedBlockingQueue<Job> Jobqueue,WorkState Ws){
jcs = Jcs;
jobqueue = Jobqueue;
ws = Ws;
}
public void run(){
try{
BufferedInputStream bis = new BufferedInputStream(jcs.GetSocket().getInputStream());
ObjectInputStream ois = new ObjectInputStream(bis);
ObjectOutputStream oos = new ObjectOutputStream(jcs.GetSocket().getOutputStream());
Object obj = null;
while(true){
try {
obj = ois.readObject();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
Job job = (Job) obj;
JobBack back= new JobBack(ws.GetState());
oos.writeObject(back);
oos.flush();
synchronized(jobqueue){
jobqueue.add(job);
job.fileReceive(jcs.GetSocket(),oos);
job.fileReceive(jcs.GetSocket(),oos);
synchronized(ws){
if(ws.IsLeisure()){
ws.SetasMReady();
}
if(ws.IsMReady()){
ws.notifyAll();
}
}
}
}
}catch (IOException e){
e.printStackTrace();
}
}
}