-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobServerThread.java
More file actions
46 lines (45 loc) · 1.21 KB
/
JobServerThread.java
File metadata and controls
46 lines (45 loc) · 1.21 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
package map_reduce_demo;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
public class JobServerThread extends Thread{
LinkedBlockingQueue<Job> jobqueue;
Socket jobsocket;
WorkState ws;
public JobServerThread(LinkedBlockingQueue<Job> jq,WorkState Ws){
jobqueue = jq;
ws = Ws;
}
public void run(){
ArrayList<JobClientState> jcsarray;
jcsarray = new ArrayList<JobClientState>();
System.out.println("JobServerThread is started");
ServerSocket serversocket = null;
try {
serversocket = new ServerSocket(6688);
} catch (IOException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
while(true){
try {
jobsocket = serversocket.accept();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("A new jobclient has been connected");
JobClientState jcs = null;
try {
jcs = new JobClientState(jobsocket);
} catch (IOException e) {
e.printStackTrace();
}
jcsarray.add(jcs);
JobServerThreadSon serverThread = new JobServerThreadSon(jcs,jobqueue,ws);
serverThread.start();
}
}
}