make scheduled methoded protected, fix connection
This commit is contained in:
parent
7e25cc583c
commit
a55806e5dd
|
|
@ -50,7 +50,7 @@ public class LoginController implements LoginApi {
|
|||
private static final ConcurrentMap<String, CacheEntry> cache = new ConcurrentHashMap<>();
|
||||
|
||||
@Scheduled(fixedRate = 300000) // 5 minutes in milliseconds
|
||||
private void clearExpiredCacheEntries() {
|
||||
protected void clearExpiredCacheEntries() {
|
||||
Instant now = Instant.now();
|
||||
int initialCacheSize = cache.size();
|
||||
cache.entrySet().removeIf(entry -> entry.getValue().expiry().isBefore(now));
|
||||
|
|
|
|||
|
|
@ -163,10 +163,24 @@ public class Connection {
|
|||
private static @NotNull Configuration getConfiguration(DatabaseSettings settings) {
|
||||
PooledDataSource dataSource = new PooledDataSource();
|
||||
dataSource.setDriver("com.mysql.cj.jdbc.Driver");
|
||||
dataSource.setUrl(String.format("jdbc:mysql://%s:%d/%s", settings.host(),
|
||||
settings.port(), settings.name()));
|
||||
|
||||
String url = String.format(
|
||||
"jdbc:mysql://%s:%d/%s?useSSL=true&tcpKeepAlive=true&socketTimeout=60000&connectTimeout=10000&autoReconnect=false&useUnicode=true&characterEncoding=utf8",
|
||||
settings.host(),
|
||||
settings.port(),
|
||||
settings.name()
|
||||
);
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(settings.username());
|
||||
dataSource.setPassword(settings.password());
|
||||
|
||||
dataSource.setPoolMaximumActiveConnections(10);
|
||||
dataSource.setPoolMaximumIdleConnections(5);
|
||||
dataSource.setPoolTimeToWait(20000);
|
||||
dataSource.setPoolPingEnabled(true);
|
||||
dataSource.setPoolPingQuery("SELECT 1");
|
||||
dataSource.setPoolPingConnectionsNotUsedFor(300000); // 5 min
|
||||
|
||||
Environment environment = new Environment("production", new JdbcTransactionFactory(), dataSource);
|
||||
return new Configuration(environment);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user