0 Replies Latest reply on Jul 22, 2011 7:16 AM by Anish Bansal

    Consistent DB snapshot across threads

    Anish Bansal Newbie

      Hi All,


      I am implementing an in-memory cache. For that I am creating a scheduled task that caches entities in memory at startup and at periodic intervals.


      Some entities are dependent on another. So, dependent entities are loaded after entities (on which they are dependent) are loaded. This is all done in a multi-threaded way. So, all totally independent entries are loaded first, then all entitites dependent on them are loaded and so on.


      While loading cache, I need to be sure that all threads should be reading from same DB snapshot. Any updates to DB during cache building process will be applied to cache in subsequent cache update runs of scheduled task. For that, I am creating two new tables, one to keep track of all the modified entries (each modification is given a unique transaction Id) and other to keep track of max transaction Id till now. To ensure consistency, all threads read max transaction Id from second table and ensure that its the same as with the master thread (thread invoking all these threads).


      My question is how do I ensure that all threads see same snapshot of DB?


      I am using Seam 2.0.1.GA, JBOSS 4.2.3.GA, Oracle 10g, Hibernate. I am using seam managed, resource-local transaction for these threads by creating a new persistence unit. For other web based threads, I am using JTA transaction.


      Thanks,
      Anish