使用 shuf 来打乱一个文件中的行或是选择文件中一个随机的行。

使用jest client 6.3.1的异步方法executeAsync写ES,主线程不会结束

Elasticsearch | 作者 xulunfan1994 | 发布于2021年01月27日 | 阅读数:1890

服务端使用的是elasticsearch6.8.8版本,java端使用io.searchbox.jest 6.3.1版本的异步方法executeAsync插入数据, main方法执行完不会退出。

这个是我调用executeAsync方法的代码:
    public static void main(String[] args) throws IOException {

// Demo the JestClient
JestClient jestClient = jestClient();

// Async operations
Employee employee = new Employee();
employee.setName("Jane Doe");
employee.setTitle("Manager");
employee.setYearsOfService(20);
employee.setSkills(Arrays.asList("managing"));
jestClient.executeAsync( new Index.Builder(employee).build(), new JestResultHandler<JestResult>() {
@Override public void completed(JestResult result) {
// handle result
}
@Override public void failed(Exception ex) {
// handle exception
}
});
}


105850647-f58de500-601c-11eb-958e-af41d410c249.png

 
而使用同步方法execute执行完时,main方法能正常退出。

592d.png


希望有大佬能帮到我,多谢~
已邀请:

要回复问题请先登录注册