Linux系统 docker部署 3.5版本
请问在springboot集成nebula的时候,怎样保证session被重复使用,并且在过期后可以刷新使用,保证程序的正常运行呢
看如下图代码,在使用时session数在一直增加,访问一次,session数就增加了一次,这样下去, session就会连满了,这个该怎么解决
换成 request 模式获取,并且通过 PostConstruct 和 PreDestroy 注解去控制生成和销毁
prototype 没有自动销毁过程肯定不断生成
1 个赞
您好,请问有实现的代码,可以看一看嘛,多谢
@Slf4j
@Component
@RequestScope
public class NebulaSession {
private final NebulaPool nebulaPool;
private final NebulaProperties properties;
private Session session = null;
public NebulaSession(NebulaPool nebulaPool, NebulaProperties properties) {
this.nebulaPool = nebulaPool;
this.properties = properties;
}
@PostConstruct
public void init() throws GraphException {
try {
session = nebulaPool.getSession(properties.getUserName(), properties.getPassWord(), true);
ResultSet res = session.execute("USE " + properties.getSpace());
if (!res.isSucceeded()) {
throw new Exception("use space failed");
}
} catch (Exception e) {
throw new Exception("nebula session init failed");
}
}
/**
* Session 销毁
*/
@PreDestroy
public void destroy() {
if (session != null) {
log.debug("nebula session is released");
session.release();
}
}
public ResultSet execute(String stmt) throws Exception {
ResultSet resultSet = session.execute(stmt);
if (!resultSet.isSucceeded()) {
log.error(resultSet.getErrorMessage());
throw new Exception(resultSet.getErrorMessage());
}
return resultSet;
}
}
多谢多谢
此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。