here is my code of main class, because only thread 3 will change the shutdown
and main will not read return until thread 3 close so there no need to synchronize it. When I try to run it, the "shutdown" is printed but eclipse say that the program is still running
static Boolean shutdown = false;
public static void main(String[] args) throws InterruptedException, IOException{
System.out.println("Start Server");
final int SocketListSize = 100000;
final int AccListSize = 1000000;
ServerSocket serverSocket;
List<Socket> socketList = Collections.synchronizedList(new ArrayList<Socket>(SocketListSize));
List<Request> requestList = Collections.synchronizedList(new ArrayList<Request>(SocketListSize));
ArrayList<BankAccount> bankAccList = new ArrayList<BankAccount>(AccListSize);
serverSocket = new ServerSocket(1234);
serverSocket.setSoTimeout(50000);
Thread Thread_1 = new Thread(new scanSocketThread(serverSocket, socketList));
Thread Thread_2 = new Thread(new getRequestThread(socketList, requestList));
Thread Thread_3 = new Thread(new ServiceThread(requestList, bankAccList));
Thread_1.start();
System.out.println("thread 1 start");
Thread_2.start();
System.out.println("thread 2 start");
Thread_3.start();
System.out.println("thread 3 start");
Thread_3.join();
System.out.println("thread 3 close");
Thread_1.interrupt();
System.out.println("thread 1 close");
Thread_2.interrupt();
System.out.println("thread 2 close");
if(shutdown == true){
System.out.println("shutdown");
return;
}
Here is what I get
thread 3 close
thread 1 close
thread 2 close
shutdown