mysql-binlog-connector-java
mysql-binlog-connector-java copied to clipboard
Best practice to interrupt a client
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 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.
But we need to disconnect when user want to shut down , adding timeout in connect seems not suit our case.