zapr-oss / druidry

Java based Druid Query Generator library
Apache License 2.0
193 stars 88 forks source link

DruidJerseyClient is not thread-safe #96

Open ethendev opened 5 years ago

ethendev commented 5 years ago

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

截图

Robinub commented 5 years ago

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

ethendev commented 5 years ago

@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?

Robinub commented 5 years ago

@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.