druidry icon indicating copy to clipboard operation
druidry copied to clipboard

DruidJerseyClient is not thread-safe

Open ethendev opened this issue 5 years ago • 3 comments

The connect() and close() methods in DruidJerseyClient class are not thread-safe which will throw an exception in a multi-threaded environment.

截图

ethendev avatar Jun 10 '19 14:06 ethendev

Is there a solution? I get a problem, the DruidResponse cannot be resolved, and how to deal with it?

Robinub avatar Jun 18 '19 02:06 Robinub

@Robinub You can use ThreadLocal in DruidJerseyClient class, please refer to this PR.

Or you can call connect() method when the application starts and close() method when the application exits.

@SpringBootApplication
public class MyApplication {

	@Autowired
	private DruidClient druidClient;

	@PostConstruct
	public void init() throws ConnectionException {
		druidClient.connect();
	}

	@PreDestroy
	public void destroy() throws ConnectionException {
		druidClient.close();
	}

	public static void main(String[] args) {
		SpringApplication.run(MyApplication .class, args);
	}

}

the DruidResponse cannot be resolved, Can you provide more detailed error information?

ethendev avatar Jun 18 '19 03:06 ethendev

@ethendev Thank you! The DruidResponse class is not created in the jar file, but now I use the HashMap to receive the results of querying instead.

Robinub avatar Jun 19 '19 06:06 Robinub