Backend Development 8 min read

Boost Spring Boot 3 Performance: Caching, Actuator, Async & DB Tuning

This guide explains how to improve Spring Boot 3 applications by using Actuator for monitoring, enabling caching, optimizing database connections with HikariCP, and applying asynchronous request handling and tasks to achieve faster response times and better resource utilization.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Boost Spring Boot 3 Performance: Caching, Actuator, Async & DB Tuning

1. Introduction

As applications grow, performance bottlenecks appear. Enhancing Spring Boot applications improves response speed, resource utilization, and resilience. This article presents key points and strategies for speeding up Spring Boot, focusing on Actuator, caching, and efficient database connections.

2. Optimization Strategies

2.1 Actuator

Use Spring Boot Actuator to monitor and control the application. Add the starter dependency and enable endpoints in the configuration file.

<code>&lt;dependency&gt;
  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
&lt;/dependency&gt;
</code>

Configure endpoints in

application.yml

(or .properties):

<code>management:
  server:
    port: 8002
  endpoints:
    web:
      base-path: /ac
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always
      show-components: always
      roles:
        - ACTUATOR
</code>

2.2 Caching

Enable caching to reduce load and latency.

<code>@SpringBootApplication
@EnableCaching
public class PackApplication {
    public static void main(String[] args) {
        SpringApplication.run(PackApplication.class, args);
    }
}
</code>

Add cache starter and provider (e.g., EhCache):

<code>&lt;dependency&gt;
  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  &lt;artifactId&gt;spring-boot-starter-cache&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
  &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
&lt;/dependency&gt;
</code>

@Cacheable : cache method return value.

@CachePut : update cache with method result.

@CacheEvict : remove entries from cache.

Example usage:

<code>@Resource
private UserRepository userRepository;
@Cacheable("users")
public Users queryUserById(Long id) {
    return userRepository.findById(id).orElse(null);
}
</code>

2.3 Database Optimization

Database interaction is often a bottleneck. Use HikariCP for connection pooling and follow best practices such as proper indexing, batch operations, and lazy loading.

<code>spring:
  datasource:
    hikari:
      minimumIdle: 100
      maximumPoolSize: 100
      autoCommit: true
      idleTimeout: 30000
      poolName: MasterDatabookHikariCP
      maxLifetime: 1800000
      connectionTimeout: 30000
      connectionTestQuery: SELECT 1
</code>

JPA/Hibernate tips: use

FetchType.LAZY

, enable second‑level cache, write optimized JPQL/native queries.

<code>@Entity
public class Customer {
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "order")
    private Set&lt;Order&gt; orders;
}
</code>

2.4 Asynchronous Requests

Leverage Servlet 3.0 async support, DeferredResult, Callable, or reactive WebClient to increase throughput.

<code>@PostMapping
public Callable<String> processUpload(final MultipartFile file) {
    return () -> "success";
}
</code>
<code>@Resource
private WebClient webClient;
public Flux<Map> chat(Mono<Map<String, Object>> body) {
    return webClient.post()
        .uri("/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?...")
        .contentType(MediaType.APPLICATION_JSON)
        .body(body, Map.class)
        .retrieve()
        .bodyToFlux(Map.class);
}
</code>
<code>@GetMapping(path="/events", produces=MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter handle() {
    SseEmitter emitter = new SseEmitter();
    return emitter;
}
</code>

2.5 Asynchronous Tasks

Use

@Async

with a dedicated thread pool for background work.

<code>@Configuration
@EnableAsync
public class AsyncConfig {}

@Async
public void dataTransform() {
    // time‑consuming task
}
</code>

Conclusion

Optimizing Spring Boot performance requires analysis, caching, efficient database access, and proper async handling. Applying these practices yields high‑performance, scalable applications.

JavaPerformance OptimizationDatabaseCachingSpring BootAsyncActuator
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.