Reputation: 169
I have a server thread that is listening on a socket. With a statement like this:
Socket client = serverSocket.accept();
What actually happens to the thread that calls this accept function? The javadoc says "Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made." Does "block" mean a form of busy waiting or is the thread suspended/in sleep until it gets a request as an interrupt or something? Also, Can this behaviour be generalized for all blocking function calls on socket like read etc...
Upvotes: 0
Views: 444
Reputation: 10089
It depends on the implementation. Not only how Java is implemented but also how the runtime library and OS system calls that Java is calling are implemented. However, blocking to wait for a file handle to be available is the type of thing an OS can optimize, so these calls tend to be non-busy waits. So, you cannot be sure, but maybe.
Upvotes: -1
Reputation: 1819
simply put, the thread simply stops and waits for a connection to be made. when a connection is made, it will continue on to the next instructions.
Upvotes: 2