Forums Register Login

enabling transactional row/key level locking in ehcache

+Pie Number of slices to send: Send
We are trying to avoid processing similar requests that arrive at same time and return the result of the first successfully processed request. We do this by simply ignoring duplicates by making an entry in cache that there was already a request with a similar known key. But this fails if threads arrive at the same time and all of them successfully do a put even before gets start working or if the first request fails.

In an example of two threads thread1, thread2 arriving at the same time thread1 leading thread2 in put:
1. If two threads arrive at the same time and attempt to make an entry in ehcache at the same time, how can we force ehcache to allow only one entry and fail the next ones by using putIfAbsent or any other means. How do we enable a row level locking with dirty read? Is there a corresponding annotation to do this explicit write/read locking as well or does putIfAbsent does this by default http://ehcache.org/documentation/2.8/apis/explicitlocking? I know the default replace/putIfAbsent behavior is atomic, but still want to confirm if this is true, otherwise why do we need read/write locks?
2. Is it possible for the remaining threads to "wait on a put like acquiring a lock" or say we open a transaction on the first thread that is processing the request and will not put a value until it succeeds?

All of this in a distributed ehcache context.
+Pie Number of slices to send: Send
 

rad kri


- Please read the Naming Policy of java ranch here.
If you think it's inappropriate you can change the name here.
+Pie Number of slices to send: Send
My name means no offense to anyone and there is nothing wrong in staying anonymous or having such a name .
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2311 times.
Similar Threads
Please explain synchronization logic in this example
Am I right about wait() and notifyAll()
A few questions on wait(), sleep(int) and InterruptedException
One file should be processed by one thread
Doubt on Thread Interrupt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:12:58.