I have a connection with a Docker Client. The problem is that it runs 2 times per second (it's a thread). It's inefficient to build the same connection every time.
I want to run this function to build the string once and store it in a variable and just return the variable every time it is needed rather than rebuilding the same string over and over. How can I do it?
public class Docker {
public static DockerClient dockerClient() {
DockerClient dockerClient;
try {
Settings settings = Settings.getSettings();
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://" + settings.getDockerIP() + ":" + settings.getDockerPort())
.withDockerConfig("/home/user/.docker/config.json")
.build();
dockerClient = DockerClientBuilder.getInstance(config).build();
return dockerClient;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}