I've got a pair of threads running a Socket and ServerSocket:
runThreadA() {
// Connects to B, or fails if B is not yet accepting
socket.connect();
}
runThreadB() {
// Blocks until another thread connects
serverSocket.accept();
}
Is there a way I can guarantee that B calls accept() and blocks before A calls connect()?
Check CyclicBarrier and CountDownLatch which can help you make the threads to wait each other, they might be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With