Let's take an example:
public class DBServer { static boolean listening = false; private static ServerSocket serverSocket = null; private static Socket clientSocket = null; static List<ClientThread> users = null; public static void main(String[] args) { users= new LinkedList(); int portNumber = 0;
Suppose that 3 users are currently connected to the server (User 0, User 1, User 2).
User 1 gets an internal lock for user 0. Iβm sure User 2 cannot get a lock for user 0 while User 1 still has this. Can user 0 independently change the value of c with method2() , while the lock is held by user 1? If so, is there a way to make variable c synchronized between a thread that owns it and other threads?
java multithreading
Akash Agarwal Feb 05 '16 at 6:46 2016-02-05 06:46
source share