I'm writing an adapter for redission client to use in our application, I'm not sure if it is a good design to close the client in the finalize block. Below is the code. Please let me know
private static final RedissonClient client;
static {
File configFile = Paths.get(Constants.ConfigDir, "cache-
config.yml").toFile();
try {
client = Redisson.create(Config.fromYAML(configFile));
} catch (IOException e) {
throw new UnableToCreateCacheClientException(e.getMessage() + e.getStackTrace(), e.getCause());
}
}
@Override
protected void finalize() throws Throwable {
super.finalize();
client.shutdown();
}
public static RedissonClient getClient() {
return client;
}
EDIT : I'm interested in knowing the right design to close a static final connection object in a web app. I cannot close it in a finally block of a method because the client will be used by multiple methods in multiple classes