make scheduled methoded protected, fix connection

This commit is contained in:
akastijn 2025-10-21 22:22:43 +02:00
parent 7e25cc583c
commit a55806e5dd
2 changed files with 17 additions and 3 deletions

View File

@ -50,7 +50,7 @@ public class LoginController implements LoginApi {
private static final ConcurrentMap<String, CacheEntry> cache = new ConcurrentHashMap<>(); private static final ConcurrentMap<String, CacheEntry> cache = new ConcurrentHashMap<>();
@Scheduled(fixedRate = 300000) // 5 minutes in milliseconds @Scheduled(fixedRate = 300000) // 5 minutes in milliseconds
private void clearExpiredCacheEntries() { protected void clearExpiredCacheEntries() {
Instant now = Instant.now(); Instant now = Instant.now();
int initialCacheSize = cache.size(); int initialCacheSize = cache.size();
cache.entrySet().removeIf(entry -> entry.getValue().expiry().isBefore(now)); cache.entrySet().removeIf(entry -> entry.getValue().expiry().isBefore(now));

View File

@ -163,10 +163,24 @@ public class Connection {
private static @NotNull Configuration getConfiguration(DatabaseSettings settings) { private static @NotNull Configuration getConfiguration(DatabaseSettings settings) {
PooledDataSource dataSource = new PooledDataSource(); PooledDataSource dataSource = new PooledDataSource();
dataSource.setDriver("com.mysql.cj.jdbc.Driver"); 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.setUsername(settings.username());
dataSource.setPassword(settings.password()); 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); Environment environment = new Environment("production", new JdbcTransactionFactory(), dataSource);
return new Configuration(environment); return new Configuration(environment);
} }