[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
I've got exception when concurrent level autolock  XML
Forum Index -> Terracotta for Web Sessions
Author Message
msbaek71

journeyman

Joined: 05/08/2007 00:00:47
Messages: 31
Offline

Hi

I put a many(about 100,000,000) objects into a map. Count object resides in map. It provides increase/decrease method for change it's count no.
When I set lock level to "write", the synchronized block causes above 10 seconds wait time in load test evironment. I think "write" lock cause the wait because it locks the entire entry in the map.

Followings are my questions about this situation:

Q1. Is there any solution tp lock an entry in the map instead of locking entire map ?

Q2. Can I use concurrent lock level if there're no solution for Q1 ?
The count object in the map has only increase and decrease method. I don't mind the sequece of method calls.

Any comment will be helpful to me ...
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

msbaek71 wrote:
Hi

Q1. Is there any solution tp lock an entry in the map instead of locking entire map ?
 


Absolutely. There is a best practice around this. You should use a read lock around your map.get, and then a write lock on the method for the Count object.

For example:
Code:
public class Count 
 {
   int count = 0;
 
   public synchronized increment() { count++; }
   public synchronized decrement() { count--; }
 }
 
 public MyClass
 {
   ...
   public void incrementCount(String key) 
   {
     Count count;
     
     synchronized (map)
       count = (Count) map.get(key);
     }
 
     count.increment();
   }
 }
 


In the above code, you should put a read lock on the MyClass.incrementCount method, and write locks on the Count.increment and Count.decrement methods.

msbaek71 wrote:
Q2. Can I use concurrent lock level if there're no solution for Q1 ?
The count object in the map has only increase and decrease method. I don't mind the sequece of method calls.
 


In general you shouldn't use the concurrent lock level.
[WWW]
 
Forum Index -> Terracotta for Web Sessions
Go to:   
Powered by JForum 2.1.7 © JForum Team