mysql-binlog-connector-java icon indicating copy to clipboard operation
mysql-binlog-connector-java copied to clipboard

Best practice to interrupt a client

Open zzt93 opened this issue 7 years ago • 2 comments

Now, we have a worker thread to connect to remote mysql and listen event. When shutting down, how to close the client?

For the time being, we do the following, but sometimes it fail to close the client & thread:

  // when shutting down
  client.disconnect();


   // interrupt in runnable
    while (!Thread.currentThread().isInterrupted()) {
      try {
        client.connect();
      } 
    }


zzt93 avatar Oct 12 '18 06:10 zzt93

@zzt93 You can use the overload of BinaryLogClient.connect() that expects a timeout; it creates and uses a dedicated thread so you don't have to create one or interrupt it yourself.

ahmedahamid avatar Jun 29 '19 21:06 ahmedahamid

But we need to disconnect when user want to shut down , adding timeout in connect seems not suit our case.

zzt93 avatar Jul 01 '19 13:07 zzt93