Commit 4ffce4c0 by 王祖波

初始化holo

parent 58b0e702
package com.gic.haoban.manage.service.dao.mapper.content.holo;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpUtil;
......@@ -14,6 +18,7 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
......@@ -29,7 +34,7 @@ import java.util.concurrent.TimeUnit;
@Component
public class HoloDataSource implements InitializingBean, DisposableBean {
HoloClient client;
private volatile HoloClient client;
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
......@@ -43,9 +48,6 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
log.info("holo链接初始化获取授权信息失败");
return;
}
if (this.client != null) {
this.client.close();
}
String holoUserName = holoAuth.getKey();
String holoPassword = holoAuth.getValue();
HoloConfig holoConfig = new HoloConfig();
......@@ -53,8 +55,13 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
holoConfig.setUsername(holoUserName);
holoConfig.setPassword(holoPassword);
holoConfig.setConnectionMaxIdleMs(13000);
this.client = new HoloClient(holoConfig);
this.client.setAsyncCommit(false);
HoloClient newClient = new HoloClient(holoConfig);
newClient.setAsyncCommit(false);
if (this.client != null) {
this.client.close();
this.client = null;
}
this.client = newClient;
log.info("holo链接初始化完成");
}catch (Exception ex) {
log.info("初始化client 异常 >>>", ex);
......@@ -74,7 +81,12 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
if (client == null) {
this.init();
}
scheduler.scheduleAtFixedRate(this::reinitialize, 12, 12, TimeUnit.HOURS);
DateTime now = DateUtil.date();
Date todayTwo = DateUtil.beginOfDay(now).offset(DateField.HOUR_OF_DAY, 2);
if (now.after(todayTwo)) {
todayTwo = DateUtil.offsetDay(todayTwo, 1);
}
scheduler.scheduleAtFixedRate(this::reinitialize, DateUtil.between(now,todayTwo, DateUnit.SECOND,true), 24 * 60 * 60, TimeUnit.SECONDS);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment