java - 多线程ThreadLocal相关求助
黄舟
黄舟 2017-04-18 09:51:54
0
5
728

当前项目的connection都是放在ThreadLocal里面的。由于我的某个功能操作有部分打算异步处理,new Thread(()->{//.......}).start() 这样就导致无法使用dao了。因为dao需要的connection在ThreadLocal中。

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
小葫芦

The connection must be released after each use. The next time you connect, just go to threadlocal to get the value. I don’t understand what you mean.

刘奇

When creating a new Thread, take the connection out of ThreadLocal and pass it in

左手右手慢动作

Isn’t there a way to get the connection?

阿神

Just write the execution part independently, so you don’t need to pass the dao to Thread

左手右手慢动作

If this asynchronous operation is non-transaction related to the previous logic. That is to say, they are not in the same transaction.
Then you can use a new link.

If there is a transaction, this old link must be used. This connection object can only be passed to the thread.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!