Skip to content

AbstractRegistryFactory have a piece of redundant code #2685

Closed

Description

@jingui123

I have found a piece of redundant code, may be is I do not understand.
in AbstractRegistryFactory class, there are two variables,one is LOCK,the other is REGISTRIES,as follows :
private static final ReentrantLock LOCK = new ReentrantLock();

// Registry Collection Map<RegistryAddress, Registry>
private static final Map<String, Registry> REGISTRIES = new ConcurrentHashMap<String, Registry>();

but when we use REGISTRIES.put() , the section of code is locked. so I think REGISTRIES will be better to modify HashMap.
example:
public Registry getRegistry(URL url) {
....
LOCK.lock();
REGISTRIES.put(key, registry);
LOCK.unlock();
}
public static void destroyAll() {
....
LOCK.lock();
REGISTRIES.clear();
LOCK.unlock();
}

Environment

  • Dubbo version: 2.7.0-SNAPSHOT
  • Java version: jdk1.8

Activity

  1. carryxyh commented on Oct 26, 2018

    @carryxyh
    Member

    Hi, would u pls send a pr to fix this?

  2. zonghaishang commented on Oct 29, 2018

    @zonghaishang
    Member

    // Lock the registry access process to ensure a single instance of the registry

  3. carryxyh commented on Oct 29, 2018

    @carryxyh
    Member

    Yes, but seems like the REGISTRIES field could change to hashmap.
    How do u think about it? @zonghaishang

  4. lllichen commented on Oct 29, 2018

    @lllichen
    Contributor

    public static Collection<Registry> getRegistries() { return Collections.unmodifiableCollection(REGISTRIES.values()); }
    is REGISTRIES.values() escape ?

  5. carryxyh commented on Oct 29, 2018

    @carryxyh
    Member

    I know.
    But hashmap.values is also thread safe.

  6. jingui123 commented on Oct 29, 2018

    @jingui123
    ContributorAuthor

    so,do the issue need to be modified to hashmap?

  7. carryxyh commented on Oct 29, 2018

    @carryxyh
    Member

    Hi, @jingui123
    U can send a pr and let more people review it. They will give their suggestions.
    :)

  8. jingui123 commented on Oct 29, 2018

    @jingui123
    ContributorAuthor

    ok, i will try it

  9. carryxyh commented on Oct 29, 2018

    @carryxyh
    Member

    Thx for your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions