Jens,
thanks for your kind answer. I'll let you know if what you suggest will fix 
our problems.



Il giorno lunedì 4 novembre 2013 19:28:04 UTC+1, Jens ha scritto:
>
> Is the HashMap get/put code inside getFactory(String persistenceUnit) 
> synchronized? If not there is a chance that you create more than one 
> factory if you do not have an entry in your HashMap<String, 
> EntityManagerFactory> instance yet. HashMap is not thread safe and if x 
> threads call getFactory(String) and you don't have an entry yet then its 
> likely that your code creates x EntityManagerFactory instances, each with 
> at least one EntityManager (through getFactory(..).createEntityManager()), 
> but only one EntityManagerFactory will be stored in your map. Thus you can 
> never clear x-1 EntityManagers.
>
> Now when the user logs out you close the factory and remove it from the 
> map. Next time multiple users login in parallel you are back at the above 
> situation where you might create more factories than you think, each with 
> an entityManager attached that you can never close.
>
> So make sure that getFactory() uses synchronized code and/or use 
> ConcurrentHashMap. Also you don't have to close the Factory at all. We do 
> something very similar in our app and we only close the Factory upon 
> undeployment of old apps. So once a EntityManagerFactory is created for a 
> customer we use it forever. We don't have any issues with it. 
>
>
> -- J.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to