Maybe one solution is to chance InstanceSynchronization in the following way

       public void afterCompletion(int status)
       {

         // This is an independent point of entry. We need to make sure the
         // thread is associated with the right context class loader
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();

Thread.currentThread().setContextClassLoader(container.getClassLoader());

         try
         {

          //DEBUG Logger.debug("afterCompletion called for ctx
"+ctx.hashCode());

          // If rolled back -> invalidate instance
          // If removed -> send back to the pool
          if (status == Status.STATUS_ROLLEDBACK || ctx.getId() == null) {

              try {

                     // NEW CODE HERE.  Put in a synch block.
                     synchronized(container.getInstanceCache().getCacheLock())
                     {
                 // finish the transaction association
                 ctx.setTransaction(null);

                 // remove from the cache
                 container.getInstanceCache().remove(ctx.getCacheKey());

                 // return to pool
                 container.getInstancePool().free(ctx);
                   }

              } catch (Exception e) {
                 // Ignore
              }


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Bill
> Burke
> Sent: Wednesday, June 06, 2001 9:39 PM
> To: Jboss-Development@Lists. Sourceforge. Net
> Subject: [JBoss-dev] race condition between EntityInstanceInterceptor
> and InstanceSynchronization?
>
>
> All,
>
> I'm wondering if I've found a race condition bewteen
> EntityInstanceInterceptor and
> EntitySynchronizationInterceptor.InstanceSynchronization.
>
> Scenario:
> ====================================================
> Transaction A                               Transaction B
>
> Grab and lock Entity 123
>                                             Wait for Entity 123 to get
> release from Trans A
>                                             in EntityInstanceInterceptor
>
> Rollback
>
> in InstanceSynchronization.afterCompletion()
> if (status == Status.STATUS_ROLLEDBACK ...
>    call ctx.setTransaction(null);
>
>                                             in EntityInstanceInterceptor:
>                                             // Next code returns null
>                                             Transaction tx =
> ctx.getTransaction();
> // remove from the cache
> container.getInstanceCache().remove(ctx.getCacheKey());
>
> // return to pool
> container.getInstancePool().free(ctx);
>
>                                             Thread continues with a freed
> Context!!!!
> ======================================================
>
> Am I missing something here?  How to fix if I'm not?
>
> The reason I've been looking into this is because I'm seeing some
> very weird
> behaviour where an EntityBean is totally out of whack with what is really
> within the database. The EntityBean actually has the data of a different
> EntityBean.  When I stop accessing this EntityBean after many different
> calls within succession and within different transactions the problem
> disappears after awhile and the EntityBean seems to revert to
> what is stored
> within the database. My guess is that the Bean gets dump from the
> InstanceCache.
>
> Regards,
> Bill
>
>
>
> _______________________________________________
> Jboss-development mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-development
>



_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to