Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (5)
master
dev5
dev4
dev3
dev1
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (5)
master
dev5
dev4
dev3
dev1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (5)
master
dev5
dev4
dev3
dev1
czqth
/
HighPerformanceConfig.java
czqth
/
HighPerformanceConfig.java
HighPerformanceConfig.java 3.77 KB
Copy Edit Raw Blame History
胡培培 authored 2025年11月19日 14:04 +08:00 . 1
package com.example.messagequeue.config;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;//
/**
* 高性能配置类
* 配置缓存、线程池和事务管理
*/
@Configuration
@EnableCaching
@EnableAsync
@EnableTransactionManagement
public class HighPerformanceConfig {
/**
* 配置Caffeine缓存管理器
*/
@Bean
public CacheManager cacheManager() {
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
cacheManager.setCaffeine(Caffeine.newBuilder()
// 初始容量
.initialCapacity(100)
// 最大容量
.maximumSize(1000)
// 写入后过期时间(5分钟)
.expireAfterWrite(java.time.Duration.ofMinutes(5))
// 记录命中率等统计信息
.recordStats());
return cacheManager;
}
/**
* 配置异步任务执行器
*/
@Bean(name = "messageTaskExecutor")
public Executor messageTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数
executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
// 最大线程数
executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 2);
// 队列容量
executor.setQueueCapacity(500);
// 线程名前缀
executor.setThreadNamePrefix("MessageExecutor-");
// 拒绝策略:调用者运行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 线程空闲时间
executor.setKeepAliveSeconds(60);
// 允许核心线程超时
executor.setAllowCoreThreadTimeOut(true);
// 等待所有任务完成后再关闭线程池
executor.setWaitForTasksToCompleteOnShutdown(true);
// 等待时间
executor.setAwaitTerminationSeconds(60);
executor.initialize();
return executor;
}
/**
* 配置数据库连接池
*/
@Bean
public HikariConfig hikariConfig() {
HikariConfig config = new HikariConfig();
// 连接池大小
config.setMaximumPoolSize(Runtime.getRuntime().availableProcessors() * 2);
// 最小空闲连接数
config.setMinimumIdle(2);
// 连接超时时间
config.setConnectionTimeout(30000);
// 空闲连接超时时间
config.setIdleTimeout(600000);
// 连接最大生命周期
config.setMaxLifetime(1800000);
// 连接测试查询
config.setConnectionTestQuery("SELECT 1");
// 数据库连接URL
config.setJdbcUrl("jdbc:h2:mem:messagequeue;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
// 数据库用户名
config.setUsername("sa");
// 数据库密码
config.setPassword("");
// 驱动类名
config.setDriverClassName("org.h2.Driver");
// 连接池名称
config.setPoolName("MessageQueuePool");
return config;
}
@Bean
public DataSource dataSource() {
return new HikariDataSource(hikariConfig());
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/level-23-java/czqth.git
git@gitee.com:level-23-java/czqth.git
level-23-java
czqth
成佳峻-张泽源-邱翔-汤明利-胡培培
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /