Why can't the sqlsession object be shared?

Because it is an 非线程安全object. each SQLSession对象都维护了一个独立的数据库连接, and the transactions and caches associated with that connection. If multiple threads share the same SQLSession object, it may cause data confusion , transaction conflicts and other problems. In addition, the SQLSession object also contains 一级缓存, 用于缓存查询结果和映射对象. If multiple threads share the same SQLSession object, cached data may be inconsistent . 一致性In order to ensure the integrity of the data 线程安全, the life cycle of the SQLSession object is usually limited to one thread , that is, each thread creates its own SQLSession object and closes it in time after use. This can avoid competition and interference between multiple threads and ensure the correctness and integrity of data.

Guess you like

Origin blog.csdn.net/m0_64365419/article/details/133417496