What is the closest to ConcurrentHashMap and NavigableMap in Java?

ilya-stromberg ilya-stromberg-2009 at yandex.ru
Thu Nov 14 13:31:38 PST 2013


On Thursday, 14 November 2013 at 21:16:15 UTC, TheFlyingFiddle 
wrote:

> If that is the case are you not limited in the way you can 
> update the map eg only in a single block?

Yes, it's probably not the best example. It's valid if you have 
only 1 synchronized block for map. But you can use something like 
this:

void bar()
{
    synchronized(map)
    {
      map[1] = 1;
    }

    synchronized(map)
    {
      map[2] = 2;
    }
}

Or this:

//Note: valid only if you have 1 function that use map
synchronized void bar()
{
      map[1] = 1;

      map[2] = 2;
}

Or this:

shared myMap;

synchronized class MyMap
{
    HashMap!(int, int) map;

    void foo()
    {
       map[1] = 1;
    }

    void bar()
    {
       map[2] = 2;
    }
}

//init map
shared static this()
{
    myMap = new MyMap();
}

Probably, it's the best example.


More information about the Digitalmars-d-learn mailing list