Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

Am I missing something - isn't this a thread leak? #432

Open
mrwilby opened this issue Jun 29, 2016 · 0 comments
Open

Am I missing something - isn't this a thread leak? #432

mrwilby opened this issue Jun 29, 2016 · 0 comments

Comments

@mrwilby
Copy link

mrwilby commented Jun 29, 2016

Where does this thread (below):

Thread watcherProcessor = new Thread("ZookeeperClient-watcherProcessor") {

get cleaned up when close() is called? I see a ton of these threads lingering around in one open source project we are using.

public ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Credentials credentials,
Optional chrootPath, Iterable zooKeeperServers) {
this.sessionTimeoutMs = Preconditions.checkNotNull(sessionTimeout).as(Time.MILLISECONDS);
this.credentials = Preconditions.checkNotNull(credentials);

if (chrootPath.isPresent()) {
  PathUtils.validatePath(chrootPath.get());
}

Preconditions.checkNotNull(zooKeeperServers);
Preconditions.checkArgument(!Iterables.isEmpty(zooKeeperServers),
    "Must present at least 1 ZK server");

Thread watcherProcessor = new Thread("ZookeeperClient-watcherProcessor") {
  @Override
  public void run() {
    while (true) {
      try {
        WatchedEvent event = eventQueue.take();
        for (Watcher watcher : watchers) {
          watcher.process(event);
        }
      } catch (InterruptedException e) { /* ignore */ }
    }
  }
};
watcherProcessor.setDaemon(true);
watcherProcessor.start();

Iterable<String> servers =
    Iterables.transform(ImmutableSet.copyOf(zooKeeperServers),
        InetSocketAddressHelper.INET_TO_STR);
this.zooKeeperServers = Joiner.on(',').join(servers);
this.connectString = this.zooKeeperServers.concat(chrootPath.or(""));

}

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant