-2
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MyServer {
    //定义保存所有Socket的ArrayList,并将其包装为线程安全
    public static List<Socket> socketList = Collections.synchronizedList(new ArrayList<>());
    public static void main(String[] args)throws IOException{
        ServerSocket ss=new ServerSocket(3000);
        while(true){
            Socket s=ss.accept();
            socketList.add(s);
            new Thread(new ServerThread(s)).start();
        }
    }
}

Why I run the program,the Console shows that"Exception in thread "main" java.lang.Error: Unresolved compilation problem: at com.eyck.inet.MyServer.main(MyServer.java:14)"
the error seems in line 9.

1

1 Answer 1

0

after modifying the line 9 to

    public static List<Socket> socketList
       =Collections.synchronizedList(new ArrayList<Socket>());

can solve the question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.