Search code examples
javastringmultithreadinginternsynchronize

Running 2 Tomcat Servers using different ports with intern() will lock same id or no?


In my Tomcat server Java Code I'am using the following code:

int port = 11111;
rmiConnectToMainServer(port);
id = request.getParameter("id").intern();
synchronized(id) {
    //call SaleFunction();
}

and in another Tomcat Server Where the port in

int port = 22222;

The question is: Does the String.intern() call use another pool of strings?? or no??

lets say a clients that has id=1234 is buying from both Tomcat Server at the same time, will he be locked ??? or can buy without any lock ???

Please help me, my app is now online .. And I'm afraid If something is wrong.

Thank you in advance


Solution

  • One String pool per JVM, so as your Tomcat instances are running in different JVMs your "id" won't be shared.