You have the new InitialContext() part in loop too? That's a bad practice. Each of that is going to create a separate connection and end up with issues like this. Also remember to do initialContext.close() wherever appropriate.

Not really, that's been done as a part of testSetup which is guaranteed to be called once per thread. However, I can try adding close() call at the end to see if that makes any difference..

Ah ok, so each thread is creating the InitialContext and I guess you have more than 40 such threads running simultaneously. Looking at the remoting code, although there's a property which allows this to be configured, it isn't used in any part of the code. So I don't see a way to configure this currently.