Stolen from:
"on the server side, when a client connects to the server socket, a new thread is forked to deal with the incoming call. "
so how can i get a control over these client threads so that i can make my client 1 wait till client 2 shows up and then perform whatever they need to perform?
Thank you.
I agree with @EJP that this is a very strange requirement. The solution I will offer should work but is normally something you absolutely don't want to do, because it blocks a thread causing bad usability and scalability.
You can achieve this using a CountDownLatch
Have a static CountDownLatch
set to 1
public class RmiEndPoint{
static CountDownLatch startSignal = new CountDownLatch(1);
Client 2 counts it down
public void executedByClient2(){
SharedLock.countDown();
}
Client 1 waits on it
public void executedByClient1(){
SharedLock.await();
// do whatever you want to do
}
}
In real code you definetly want to have some timeouts so your app doesn't hang for ever if client2 doesn't show up