Compare commits

...

1 Commits

Author SHA1 Message Date
tomsun28
2c4d3d80b0 [collector]fix 由于链接复用不佳造成创建过多链接监控异常 2022-03-14 20:34:47 +08:00
3 changed files with 7 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package com.usthe.collector.collect.common.cache;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
/**
* 缓存key唯一标识符
@@ -10,6 +11,7 @@ import lombok.Data;
*/
@Data
@Builder
@ToString
public class CacheIdentifier {
private String ip;

View File

@@ -21,9 +21,9 @@ import java.util.concurrent.TimeUnit;
public class CommonCache {
/**
* 默认缓存时间 10minute
* 默认缓存时间 800s
*/
private static final long DEFAULT_CACHE_TIMEOUT = 10 * 60 * 1000L;
private static final long DEFAULT_CACHE_TIMEOUT = 800 * 1000L;
/**
* 默认最大缓存数量
@@ -173,9 +173,11 @@ public class CommonCache {
public Optional<Object> getCache(Object key, boolean refreshCache) {
Long[] cacheTime = timeoutMap.get(key);
if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) {
log.warn("[cache] not hit the cache, key {}.", key);
return Optional.empty();
}
if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) {
log.warn("[cache] is timeout, key {}.", key);
timeoutMap.remove(key);
cacheMap.remove(key);
return Optional.empty();

View File

@@ -134,7 +134,7 @@ public class JdbcCommonCollect extends AbstractCollect {
// 设置查询最大行数1000行
statement.setMaxRows(1000);
JdbcConnect jdbcConnect = new JdbcConnect(connection);
CommonCache.getInstance().addCache(identifier, jdbcConnect, 10000L);
CommonCache.getInstance().addCache(identifier, jdbcConnect);
return statement;
}