There is a piece of code:
public class Test { private final Socket socket; private final ObjectOutputStream out; private final ObjectInputStream in; public Connection(Socket socket) throws IOException { this.socket = socket; out = new ObjectOutputStream(socket.getOutputStream()); in = new ObjectInputStream(socket.getInputStream()); } public void sendSomeThing1(Message message) { synchronized (out) { out.writeObject(message); } } public synchronized void sendSomeThing2 (Message message) { out.writeObject(message); } } Do I understand correctly that in sendSomeThing1 I only block the out object? This means that other threads can use the object and methods of the Test class.
But when using void sendSomeThing2, threads will not be able to use methods of the TESE class at the same time, will they wait for their turn?
Also what are the differences between
synchronized (**out**) { out.writeObject(message); } and
synchronized (**this**) { out.writeObject(message); }