前言 不正确的日志打印不但会降低程序运行性能,还会占用大量IO资源和硬盘存储空间。 本文主要总结一些能提高日志打印性能的手段。 一、通过AsyncAppender异步输出日志 我们通常使用的ConsoleAppender 和 RollingFileAppender都是同步输出日志,会阻塞程序运行。只有当日志打印完毕程序才会继续执行。 而通过AsyncAppender实现异步日志输出,会启用单独日志线程去记录日志,并且不会阻塞程序运行,可以极大的增加日志打印的吞吐量。 具体实现可以查看:logback异步输出日志详解 配置示例: 添加一个基于异步写日志的 appender,并指向原先配置的 appender即可。 <configuration> <!-- 同步输出 --> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>myapp.log</file> <encoder> <pattern>%logger{35} .... logback性能优化详解 java
I use gateway The version is 2020.0.1, It's used in communication websocket. It was used well , It turned out that something unusual happened one day :Max frame length of 65536 has been exceeded. If you read the wrong information in the newspaper, you know it's because websocket The frame of is more than the default 65536 Limit , This limitation can be found in this class in the source code reactor.netty.http.websocket.WebsocketSpec You can see it in the picture . I didn't want to solve it mysel.... Solve the problem of Max frame length of 65536 has been exceeded in websocket of spring cloud gateway webflux
用SchedulingConfigurer接口只能统一修改,要分开控制的话有多少个job就要有多少个实现。比较麻烦 配置线程池ThreadPoolTaskScheduler Copy@Configuration public class JobConfig { @Bean("taskExecutor") public ThreadPoolTaskScheduler taskExecutor() { ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler(); executor.setPoolSize(20); executor.setThreadNamePrefix("taskExecutor-"); executor.setWaitForTasksToCompleteOnShutdown(true); executor.setAwaitTerminationSeconds(300); return executor; } } 封装实现 Copy@Component @Slf4j public class Job.... 使用ThreadPoolTaskScheduler动态修改调度时间 java
前言 项目中需要监听redis的一些事件比如键删除,修改,过期等。过期事件网上有很多例子可以参考,但修改或删除事件却很少。因为redis支持发布订阅所以其他的事件类型应该也是能实现的,通过过期事件监听结合上文键空间通知,我整理了相关代码,希望帮助需要的人快速解决问题。 代码实践 网上示例的失效事件监听代码 import com.alibaba.fastjson.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframewor.... Redis监听新增、修改、删除、过期事件 redis
在MyBatis 的映射配置文件中,动态传递参数有两种方式: (1)#{} 占位符 (2)${} 拼接符 #{} 和 ${} 的区别 (1) 1)#{} 为参数占位符 ?,即sql 预编译 2)${} 为字符串替换,即 sql 拼接 (2) 1)#{}:动态解析 -> 预编译 -> 执行 2)${}:动态解析 -> 编译 -> 执行 (3) 1)#{} 的变量替换是在DBMS 中 2)${} 的变量替换是在 DBMS 外 (4) 1)变量替换后,#{} 对应的变量自动加上单引号 '' 2)变量替换后,${} 对应的变量不会加上单引号 '' (5) 1)#{} 能防止sql 注入 2)${} 不能防止sql 注入 #{} 和 ${} 的实例:假设传入参数为 1 (1)开始 1)#{}:select * from t_user where uid=#{uid} 2)${}:select * from t_user where uid= '${uid}' (2)然后 #{}:select * from t_u.... 有更新! mybatis中的#{}和${} sql
swagger 2.X是springboot用于生成在线文档的工具,基于OpenApi2 springdoc-openapi-ui 则是基于OpenApi3,可以看成是swagger3,因为导入之后一些注解的包名都是 io.swagger.v3.oas.annotations baidu出来的都被swagger 2占领了,基本搜不到文档,想要查阅请自行谷歌 文档上说springdoc-openapi-ui能够在webflux的项目中使用,尚未尝试,留几个文档地址请自行查阅 https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations https://github.com/springdoc-openapi https://springdoc.github.io/springdoc-openapi-demos/ 依赖 implementation 'org.springdoc:springdoc-openapi-ui:1.2.3' 使用 springdoc-openapi-ui作为spri.... springboot集成springdoc-openapi-ui java
1.Spring Boot Admin 是什么 Spring Boot Admin 是由 codecentric 组织开发的开源项目,使用 Spring Boot Admin 可以管理和监控你的 Spring Boot 项目。它分为客户端和服务端两部分,客户端添加到你的 Spring Boot 应用增加暴漏相关信息的 HTTP 接口,然后注册到 Spring Boot Admin 服务端,这一步骤可以直接向服务端注册,也可以通过 Eureka 或者 Consul 进行注册。而 Spring Boot Admin Server 通过 Vue.js 程序监控信息进行可视化呈现。并且支持多种事件通知操作。 2. Spring Boot Admin 服务端 Spring Boot Admin 服务端是基于 Spring Boot 项目的,如何创建一个 Spring Boot 项目这里不提,你可以参考之前文章或者从 https://start.spring.io/ 直接获得一个 Spring Boot 项目。 2.1. 添加依赖 只需要添加 web 依赖和 Spring-boot-admin-s.... 有更新! 使用 SpringBoot Admin 监控你的 SpringBoot 程序 spring