You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Dmitry Gusev (JIRA)" <ji...@apache.org> on 2015/09/07 11:51:45 UTC

[jira] [Created] (TAP5-2499) Race condition in EntityManagerSource#getEntityManagerFactory

Dmitry Gusev created TAP5-2499:
----------------------------------

             Summary: Race condition in EntityManagerSource#getEntityManagerFactory
                 Key: TAP5-2499
                 URL: https://issues.apache.org/jira/browse/TAP5-2499
             Project: Tapestry 5
          Issue Type: Bug
          Components: tapestry-jpa
    Affects Versions: 5.3.8, 5.4
            Reporter: Dmitry Gusev


On application start if more than one thread needs an entity manager more than one instance of EntityManagerFactory may be created.

This is undesirable, because EMF may use a connection pool and creating more than one instance will lead to too many open database connections.

EntityManagerSourceImpl.java:
{code}
    public EntityManagerFactory getEntityManagerFactory(final String persistenceUnitName)
    {
        EntityManagerFactory emf = entityManagerFactories.get(persistenceUnitName);

        if (emf == null)
        {
            emf = createEntityManagerFactory(persistenceUnitName);

            entityManagerFactories.put(persistenceUnitName, emf);
        }

        return emf;
    }
{code}

Above code needs some synchronization.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)