Collection values

41 views
Skip to first unread message

Vishesh Joshi

unread,
Jan 29, 2016, 5:57:58 PM1/29/16
to concurrent-trees-discuss
Hi,

Is there a way to have a value set, instead of a single value per key?

I put a set object myself, but I lose the property to read/write concurrency.

Any suggestions are welcome :)


Niall

unread,
Mar 30, 2016, 5:58:30 PM3/30/16
to concurrent-trees-discuss
Hi Vishesh,

Sorry I missed this.

Yes, well, there are some methods in ConcurrentRadixTree:

Those methods would allow you to extend the scope of the locks used by the tree itself, to encapsulate any other write operations you want to perform as well (for example, on the sets you mentioned).

Basically if you make a subclass of ConcurrentRadixTree, you can add your own custom method to it to leverage this as follows:

public void myCustomMethod() {
    acquireWriteLock();
    try {
        // you can call any other method(s) in the tree or perform other operations here, and no other threads will be able to modify the tree until you have finished.
    }
    finally {
        releaseWriteLock();
    }
}

While your method is executing, other _writing_ threads which try to modify the tree concurrently will be blocked. However reading threads will not be blocked by default. So this should work fine wrt reading threads as long as the implementation of the sets you will store as values in the tree will be thread-safe.

OTOH if the implementation of the sets you will store as values in the tree will NOT be thread-safe, there is another option where you can supply restrictConcurrency = true to the constructor of the ConcurrentRadixTree. This enables a mode where reading threads will be blocked as well while your method is executing. In that mode you sacrifice some concurrency.

Hope that helps,
Niall

Chris Miller

unread,
Jun 27, 2018, 7:09:27 AM6/27/18
to concurrent-trees-discuss
Is the same thing possible for the inverted tree? It doesn't seem like it but maybe I'm missing something.

I have a pub/sub implementation and want clients to be able to subscribe to messages with topics that have a certain prefix. For example, a client might subscribe to "event:printer:" and they would then receive any messages with topics like "event:printer:OutOfPaper", "event:printer:JobStarted", but not "event:light:TurnedOff". To do this efficiently (assuming infrequent subscribe/unsubscribes and a large volume of messages) seems to require an inverted tree that holds values of type Set<Client> (because multiple clients might be subscribed to the same prefix).

Any ideas on the best approach?

Regards,
Chris
Reply all
Reply to author
Forward
0 new messages