I have a case where I am using multiple threads to query from a web service. Once in a time, I have to authenticate myself to the web server because session expires after this time. I do the authorization like:
static void threadCall(){
try{
ws.query();
}
catch(AuthenticationFailException ex){
AuthAgain();
threadCall();
return;
}
}
The problem is, authentication fails for multiple threads and multiple threads want to authenticate at the same time. This slows the process so I want to authenticate for 1 thread only and want other threads to wait until authentication is done. How can I achieve this.