当前位置:网站首页>Returned object not currently part of this pool
Returned object not currently part of this pool
2022-08-05 05:05:00 【绅士jiejie】
问题背景
使用了org.apache.commons.pool2依赖来做了一些池化操作,把一些已经实例化成功的客户端池化进了对象池,通过池化加快接口的查询效率。
问题分析
以上异常翻译过来就是【返回的对象当前不属于此池】,为什么会出现这种情况,因为导致这个报错的接口允许接收多个参数,然后一并返回结果,为了提升查询效率,所以引入了多线程查询,然后每个线程运行执行的底层逻辑方法中,有一个核心逻辑就是会去对象池中拿客户端对象,如果拿不到就会创建对象池同时生成客户端对象放进对象池中。正常情况下,是不会有这种异常的,问题在于多线程并发情况下,如果底层不加锁什么的,保证同步,那么很可能就会创建出多个对象池,但其实真正有引用关系的又是最后一个生成的对象池,因此前面创建出来的一些对象,在归还对象入池时,就会发现这对象不属于最后一个被引用的对象池,就会报出【Returned object not currently part of this pool】错误。
解决方案
1.如果没有什么懒加载的想法,那么建议可以在项目启动时初始化好对象池。
2.如果怕有些对象根本用不到,一开始就初始化出来,会导致资源浪费,那么建议试试加锁,不过这样的话就会影响到整体查询效率了。
边栏推荐
猜你喜欢

creo怎么测量点到面的距离

Application status of digital twin technology in power system

how to measure distance from point to face in creo

What is ASEMI photovoltaic diode, the role of photovoltaic diode

The production method of the powered small sailboat is simple, the production method of the electric small sailboat

Flutter学习三-Flutter基本结构和原理

Excel画图

Mini Program_Dynamic setting of tabBar theme skin

ansible各个模块详解

There are a lot of 4T hard drives remaining, prompting "No space left on device" insufficient disk space
随机推荐
一篇博客通关Redis技术栈
The solution to the failure to read channel information when dedecms generates a message in the background
Excel Paint
uboot开启调试打印信息
Redis哨兵模式配置文件详解
How can Flutter parent and child components receive click events
uva1325
uva1325
Develop your own node package
LeetCode:1403. 非递增顺序的最小子序列【贪心】
Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
Flutter TapGestureRecognizer 如何工作
NPDP证书含金量高吗?跟PMP相比?
u-boot中的u-boot,dm-pre-reloc
Flutter学习三-Flutter基本结构和原理
Flutter Learning 4 - Basic UI Components
仪表板展示 | DataEase看中国:数据呈现中国资本市场
Judgment statement _switch and case
Shell(4)条件控制语句
How does the Flutter TapGestureRecognizer work