How to synchronize the action of multiple threads and make sure that only one thread can access the resource at a given point in time in EhCache
.
Asked
Active
Viewed 1,649 times
0

Sibani
- 63
- 1
- 9
2 Answers
1
I'm not sure I understand your question but let's guess. EhCache (3, I don't know about 2) is fully thread-safe.
However, if you really mean that one entry can be used by only one thread at the time, that's not something EhCache will do as this is a specific need. You need to put your own synchronisation on top of it. Using a lock or a semaphore. For example, you could lock on the retrieved value.

Henri
- 5,551
- 1
- 22
- 29
-
My issue was when we start two or more threads within a program, there may be a situation when multiple threads try to access the same resource stored in EhCache and finally they can produce unforeseen result due to concurrency issues. So, to avoid this, I have to write my own synchronization code. – Sibani Aug 17 '17 at 07:13
-
They can retrieve the entry without any issues. But of course, if they start modifying the entry, you indeed need synchronization. Ehcache can't do anything for you there. – Henri Aug 17 '17 at 15:38
-
I added my own synchronization code..but I faced the following issue- https://stackoverflow.com/questions/45834377/can-same-ehcache-object-of-same-cache-manager-be-used-by-multiple-threads – Sibani Aug 23 '17 at 08:25
0
I believe this question is close to another one of yours and cache-through could help you.

Louis Jacomet
- 13,661
- 2
- 34
- 43