• mybatis ----SqlSessionManager


    今天我们来看看这个类 有些写法还是很经典的

    public class SqlSessionManager implements SqlSessionFactory, SqlSession {

    private final SqlSessionFactory sqlSessionFactory;
    private final SqlSession sqlSessionProxy;

    private final ThreadLocal<SqlSession> localSqlSession = new ThreadLocal<>();

    private SqlSessionManager(SqlSessionFactory sqlSessionFactory) {
    this.sqlSessionFactory = sqlSessionFactory;
    this.sqlSessionProxy = (SqlSession) Proxy.newProxyInstance(
    SqlSessionFactory.class.getClassLoader(),
    new Class[]{SqlSession.class},
    new SqlSessionInterceptor());
    }

    讲两点

    1直接能看到 的threadLoacal<Sqlsession> ,说明<SqlSession> 是跟线程绑定的,每个线程里会自己的SqlSesion副本

    2Proxy 代理SqlSession 接口,SqlSessionProxy,代理的写法和使用。




  • 相关阅读:
    网页加载进度条
    BFC
    Java — 基础语法
    Python — 多进程
    Python — 进程和线程
    Python — 面向对象进阶2
    Python — 面向对象编程基础
    Linnux 05
    Linnux 04
    Linnux 03
  • 原文地址:https://www.cnblogs.com/anyehome/p/9994523.html
Copyright © 2020-2023  润新知