curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sznajder ForMailingList <bs4mailingl...@gmail.com>
Subject atomic setCount() in SharedCount
Date Thu, 17 Oct 2013 13:36:02 GMT
Hi,

In my configuration, several workers update a Sharedcount object by
increment or decrement the counter of the node.
I implemented this by this piece of code:

    public void incrementForKey(String key) throws Exception {
        SharedCount count = new SharedCount(this.framework,
                this.path + "/" + key,0);
        count.start();
        count.setCount(count.getCount()+1);
    }

However, I am worrying about the last line:
        count.setCount(count.getCount()+1);

What happens, in case, two workers concurrently, try to increment or
decrement the node value? I suppose this is not atomic and so, how can I
solve that?

Benjamin.

Mime
View raw message