Hello everyone, I got a question on synchronization, hope someone will be able to give me a clear explanation.
public void sendToAll( String message ) {
.....
synchronized( outputStreams ) {
...
""statement block""
}
}
outputStreams is an object here. I made some research and I found that its a synchronize statement .
And that the object specified in the statement is the lock. Could you please explain to me what really happens in the piece of code.
Its for a chat system, I am implementing multi threading in my chat.
This is supposed to send the "message" to all the ouputstreams(to all clients).
The object outputstreams is a list of all the output stream for all clients which have connect to the server.
But I want to know how the message is send, in parallel ? one by one ?? what is the function of lock ? Hope to get an answer soon.
Thanks in advance.