At the moment I am struggling with a bug in Sun's class java.net.Authenticator
. It seems that the Authenticator
class has a system wide static Authenticator
. This results in the following problem in my multi-threaded application.
- Thread 1 - Authenticates for User 1
- Thread 2 - Authenticates for User 2
- Thread 1 - Executes the code to download messages for User 1
At this point, the system will get the messages for User 2 instead of the messages for User 1.
I have tried searching for a solution. Many suggested trying the following code:
AuthCacheValue.setAuthCache(new AuthCacheImpl());
Authenticator.setDefault(exchangeAuthenticator);
However, this does not work for me since my application is multi-threaded (exchangeAuthenticator
will always be set to the authenticator initialized in the latest thread).
If anyone has any idea, even a hack would do at the moment, I would really appreciate that, since at the moment the only 'neat' solution is to place a synchronized
on the main execution method with a dramatic effect on performance.