Zookeeper Client Threading Model

Zookeeper client library’s threading model

  1. When we start our application, the application’s start code in the main() method is executed on the main thread.
  2. When Zookeeper object is created, the object creates two additional threads
    1. Event Thread
      1. Manages Zookeeper state change events
        1. Connection (KeeperState.SyncConnected)
        2. Disconnection (KeeperState.Disconnected)
      2. Manages all the Znode Watchers and Triggers we subscribe to.
      3. All events coming from Zookeeper are executed on the Event Thread and they are executed in the order.
    2. IO Thread
      1. We don’t interact with this thread directly.
      2. This handles all the network communication between our application and the Zookeeper servers.
      3. This handles Zookeeper’s requests and responses.
      4. This responds to pings from Zookeeper.
      5. This handles Session Management
      6. This handles Session Timeouts
      7. etc.

Links to this note