Hi everyone:
I seek help for a Tomcat web-based app I'm currently building. My web app that needs to update data quite frequently (about as much as it needs to read it), and I've been running into some stale data issues, all of which point to lack of synchronization between the Hibernate caches between Tomcat threads. Since HTTP requests to Tomcat are handled by a semi-randomly chosen Tomcat thread, I'm getting patterns such as these:
Call 1: Thread 5 - Data is good, update Call 2: Thread 5- Data is good, update Call 3: Thread 5 - Data is good, update Call 4: Thread 7 - Data is stale, returns error :( Call 5: Thread 7 - Data is stale, returns error :( Call 6: Thread 5 - Data is good, update Call 7: Thread 5 - Data is good, update Call 8: Thread 7 - Data is stale, returns error :( Call 9: Thread 7 - Data is good, update (I guess that here the cache expired and it refreshed its data from the database) Call 10: Thread 7 - Data is good, update Call 11: Thread 5 - Data is stale, returns error :( ... ...
So my best guess so far is that the caches are not being updated between threads. I've been playing around (unsuccessfully) with hibernate.cfg.xml and with ehcache.xml, trying to switch between NoCacheProvider, org.hibernate.cache.EhCacheProvider, its net.sf.ehcache version, SingletonEhCacheProvider, and others, to no avail. In desperation, I've tried to reduce the number of available threads to 1, and it hasn't worked either.
So I ask you - please help me... how do I configure my Hibernate+Tomcat app so that the cache is correctly replicated/invalidated between threads? I've worked with Hibernate for over a year before, but I had never had to build my application from scratch (until now), so I know fairly little about its configuration or caching details. All I need to do is keep my data consistent across Tomcat threads.
Thanks for reading this... and thank you more if you help me solve my problem! :D
|