openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Persist issue in multithreaded environment
Date Mon, 03 Aug 2009 17:03:29 GMT
Hi,

There should not be any need to set the Multithreaded flag to  
correctly use exactly one entity manager for a thread. The entity  
manager factory itself is thread safe.

The usual symptom for a multithreading problem is an exception thrown  
inside an implementation method that can't be explained by application  
code.

What are your symptoms?

Regards,

Craig

On Aug 3, 2009, at 6:43 AM, Claudio Di Vita wrote:

>
>
>
> Jean-Baptiste BRIAUD -- Novlog wrote:
>>
>> Did you compared using == what you think is different instance of
>> EntityManager ?
>> Reading your message tend to prove that EntityManager is shared and
>> when you think you got a new one it is not a new one.
>>
>
> Why I have to check an instance returned by a threadlocal variable ??
>
> I use the following Th ThreadLocal<EntityManager>:
>
> private static class ThreadLocalEntityManager extends
> ThreadLocal<EntityManager> {
>
>        /* (non-Javadoc)
>         * @see java.lang.ThreadLocal#get()
>         */
>        @Override
>        public EntityManager get() {
>
>            /* Get the current entity manager */
>            EntityManager em = super.get();
>
>            /* The entity manager was closed */
>            if (!em.isOpen()) {
>
>                /* Create a new entity manager */
>                em = factory.createEntityManager();
>
>                /* Update the entity manager */
>                set(em);
>            }
>
>            return em;
>        }
>
>        /* (non-Javadoc)
>         * @see java.lang.ThreadLocal#initialValue()
>         */
>        @Override
>        protected EntityManager initialValue() {
>
>            return factory.createEntityManager();
>        }
>    }
>
> Where factory is a static EntityManagerFactory.
>
> What is going wrong ??
>
> -----
> Not everything that can be counted counts, and not everything that  
> counts can
> be counted - Albert Einstein
> -- 
> View this message in context: http://n2.nabble.com/Persist-issue-in-multithreaded-environment-tp3377510p3377741.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message