SqlSession
发表于|更新于
|浏览量:
被温柔对待以后,自己也想变得温柔。——《夏目友人帐》。
参照我这个PR
在Mybatis中SqlSession类比于我们在使用原生jdbc时的Connection对象,用完需要释放。。。
我之前写的忘记释放了,导致druid监控到大量连接未释放,连接池经常占满
所以改成这种方式了

我们使用后一定要调用SqlSession#close释放连接。。。
血的教训啊,因为忘记释放导致连接池泄露,愈发让我明白自己写代码还有很多要学
相关推荐
2021-10-23
ThreadLocal子线程共享
世人缺乏的是毅力,而非气力。——雨果 昨天聊了ThreadLocal可以用作单个线程中变量共享 其底层实现其实就是个Map,用线程作为key,不信可以看这部分源码: 123456789101112131415161718192021/** * Returns the value in the current thread's copy of this * thread-local variable. If the variable has no value for the * current thread, it is first initialized to the value returned * by an invocation of the {@link #initialValue} method. * * @return the current thread's value of this thread-local */public T get() { Thread t = Thread.currentThr...
2023-09-02
TreeMap踩坑
不降志,不屈身,不追赶时髦,也不回避危险。──胡适 今天使用TreeMap踩坑了 代码如下: 12345678 @Testvoid test() { Map<Integer, Object> map = new TreeMap<>(Comparator.comparing(i -> i % 2 == 0)); map.put(2, 0); map.put(1, 0); map.put(3, 0); System.out.println(map);} 输出结果却是 1{1=0, 2=0} 这是因为Comparator里计算结果重复导致的,即便我们的key并不相同,也会被覆盖。。。 于是我们可以指定计算结果相同时策略: 123456789@Testvoid test() { Map<Integer, Object> map = new TreeMap<>(Comparator.<Integer, Boolean>comp...
2023-11-04
spring-state-machine守卫
是非之声,无翼而飞;损益之名,无胫而走。——白居易 文档: https://docs.spring.io/spring-statemachine/docs/current/reference/#configuring-guards 说白了守卫是用来判断事件执行后能否更新到下一个状态的 这里按之前提到的代码示例来示范 首先是配置为返回true,发现下面一路正常打印 然后是return false 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485package com.ruben.parent;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configura...
2021-08-11
mvc配置指定参数处理
人原来是这样健忘的,同样的一个人在短短的时间内竟然变换了两个面目,过后他又想,大概正是因为这样健忘,所以才能够在痛苦中生活下去罢。——巴金 今天遇到这样一个情况,我想使用parameter也就是?orders=[{"column":"sort","asc":false}]的方式传递参数 但我很多接口都是生成的如下写法,并且排序使用的List<OrderItem>这样的对象数组去接收 因此我需要进行全局配置,所以就有了如下代码: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110package com.ruben....
2024-10-24
AjPlus Captcha
如同明日将死那样生活,如同永远不死那样求知。——甘地 行为验证码(滑动拼图、点选文字),前后端(java)交互,包含h5/Android/IOS/flutter/uni-app的源码和实现 github: https://github.com/anji-plus/captcha 在线文档:https://ajcaptcha.beliefteam.cn/captcha-doc/简介 AJ-Captcha行为验证码,包含滑动拼图、文字点选两种方式,UI支持弹出和嵌入两种方式。后端提供Java实现,前端提供了php、angular、html、vue、uni-app、flutter、android、ios等代码示例。 1 在线体验在线体验暂时下线 2 功能概述 2.1 组件介绍 行为验证码采用嵌入式集成方式,接入方便,安全,高效。抛弃了传统字符型验证码展示-填写字符-比对答案的流程,采用验证码展示-采集用户行为-分析用户行为流程,用户只需要产生指定的行为轨迹,不需要键盘...
2024-01-04
cron-utils获取下几次执行时间
忍耐与温柔是最大的力量。——哈特 首先引入依赖: 12345<dependency> <groupId>com.cronutils</groupId> <artifactId>cron-utils</artifactId> <version>9.2.0</version></dependency> 然后是代码: 12345678910111213141516171819202122232425262728293031323334353637import com.cronutils.model.Cron;import com.cronutils.model.CronType;import com.cronutils.model.definition.CronDefinitionBuilder;import com.cronutils.model.time.ExecutionTime;import com.cronutils.parser.CronParser;im...
