We're really having a hard time trying to figure out if our code is really threadsafe. We have a web app that contains spring-injected services that use a dao layer to get to the database via Hibernate. We injected the services into INSTANCE variables in the servlet - so every request that comes in becomes a thread that uses those same service objects. The service object contains a dao object that is used to access the database via hibernate (oracle in this case).
So, for example, the contactService is an instance variable in the this servlet
this call is made from the servlet to the service
in the ContactService class we use a dao class:
and make this call:
in the ContactDao class is the method:
From what I understand the org.hibernate.Query is not threadsafe. So is it possible our code is not threadsafe because each thread started by the servlet container is using the same service and dao objects?
Servlet's instance variables are not thread safe. so the following variable might have thread safety problem.
org.hibernate.Query is not thread safe but it would not be a problem in your code, reason being you are creating hqlQuery local object rather than an instace object. Each thread (each execution) using findSupervisorContactList function would have its own hqlQuery object in the stack.