Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableFeignClients
@EnableScheduling
public class ThreeRiversBankApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.threeriversbank.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class WarmupService {

private final CreditCardService creditCardService;

/**
* Periodically calls getAllCreditCards() to keep the JVM hot, Hibernate query plan
* cache warm, and the H2 HikariCP connection pool active after idle periods.
* Runs every 5 minutes (300,000 ms) with a 1-minute (60,000 ms) initial delay.
* Delays are configurable via warmup.fixed-delay and warmup.initial-delay properties.
*/
@Scheduled(fixedDelayString = "${warmup.fixed-delay}", initialDelayString = "${warmup.initial-delay}")
public void warmup() {
log.debug("WarmupService: running scheduled warmup to keep JVM and Hibernate hot");
try {
int count = creditCardService.getAllCreditCards().size();
log.debug("WarmupService: warmup complete, {} cards loaded", count);
} catch (Exception e) {
log.warn("WarmupService: warmup query failed: {}", e.getMessage());
}
}
}
11 changes: 10 additions & 1 deletion backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ spring:
driver-class-name: org.h2.Driver
username: sa
password:
hikari:
connection-test-query: SELECT 1
keepalive-time: 300000ms
idle-timeout: 600000ms

h2:
console:
Expand All @@ -17,7 +21,7 @@ spring:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: create
show-sql: true
show-sql: false
defer-datasource-initialization: true

sql:
Expand Down Expand Up @@ -80,3 +84,8 @@ springdoc:
path: /api-docs
swagger-ui:
path: /swagger-ui.html

# Warmup scheduler configuration
warmup:
fixed-delay: 300000
initial-delay: 60000