Code sample two threads updating
The speed and efficiency of a long-running, data-intensive operation often improves when you split it into smaller operations running on multiple threads.
So you may want to reevaluate your requirements to find the best balance of isolation and performance for your specific situation. The thing is application must be very performant, it might run on 16 or maybe even 32 threads.This article discusses how you can use multithreaded programming techniques with Visual Basic® .NET to develop more efficient and responsive applications.For example each thread represents separate transaction, and first checks db for value and then depending on answer has to insert or update some fields in database(note between check, insert and commit application is doing other processings). T1 and T2 checks db and find nothing and both insert same entry. T1 checks db, find entry with old date, but on commit T2 already has updated entry to more recent date. If we use cache and synchronize access to cache we have a problem: T1 acquires lock checks db and cache if not found add to cache, release lock, commit. I'm working on creating simple custom cache with syncronization and solving problem 3. Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. See the How to Ask page for help clarifying this question. Then on top of this, you need to select your locking strategy (optimistic or pessimistic).But the problem is that another thread might be doing just the same thing on same table. Thread T1 starts transaction, then checks table ENTITY_TABLE for entry with code '111' if found updates its date, if not found inserts new entry, then commits transaction. T2 does the same, finds entry in cache going to commit. Now T2 is in bad shape, because it should insert to ENTITY_TABLE but doesn't know that. But Im interested maybe there is some more simple solution? Without transaction isolation, you will have a hard time trying to ensure transaction integrity solely in the Java domain.