博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PooledDataSource--mybatis-3-mybatis-3.2.3
阅读量:6879 次
发布时间:2019-06-26

本文共 6321 字,大约阅读时间需要 21 分钟。

 

 

org.apache.ibatis.executor.SimpleExecutor

public 
List
doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { Statement stmt = null; try { Configuration configuration = ms.getConfiguration(); StatementHandler handler = configuration.newStatementHandler(this, ms, parameter, rowBounds, resultHandler, boundSql); stmt = prepareStatement(handler, ms.getStatementLog()); return handler.
query(stmt, resultHandler); } finally { closeStatement(stmt); } } public List
doFlushStatements(boolean isRollback) throws SQLException { return Collections.emptyList(); } private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException { Statement stmt; Connection connection = getConnection(statementLog); stmt = handler.prepare(connection); handler.parameterize(stmt); return stmt; }

 

 

org.apache.ibatis.executor.BaseExecutor

protected Connection getConnection(Log statementLog) throws SQLException {    Connection connection = transaction.getConnection();    if (statementLog.isDebugEnabled()) {      return ConnectionLogger.newInstance(connection, statementLog);    } else {      return connection;    }  }

 

 

org.apache.ibatis.transaction.jdbc.JdbcTransaction

protected void openConnection() throws SQLException {    if (log.isDebugEnabled()) {      log.debug("Opening JDBC Connection");    }    connection = dataSource.getConnection();    if (level != null) {      connection.setTransactionIsolation(level.getLevel());    }    setDesiredAutoCommit(autoCommmit);  }

 

 

org.apache.ibatis.datasource.pooled.PooledDataSource

public Connection getConnection() throws SQLException {    return popConnection(dataSource.getUsername(), dataSource.getPassword()).getProxyConnection();  }

 

private PooledConnection popConnection(String username, String password) throws SQLException {    boolean countedWait = false;    PooledConnection conn = null;    long t = System.currentTimeMillis();    int localBadConnectionCount = 0;    while (conn == null) {      synchronized (state) {        if (state.idleConnections.size() > 0) {          // Pool has available connection          conn = state.idleConnections.remove(0);          if (log.isDebugEnabled()) {            log.debug("Checked out connection " + conn.getRealHashCode() + " from pool.");          }        } else {          // Pool does not have available connection          if (state.activeConnections.size() < poolMaximumActiveConnections) {            // Can create new connection            conn = new PooledConnection(dataSource.getConnection(), this);            @SuppressWarnings("unused")            //used in logging, if enabled            Connection realConn = conn.getRealConnection();            if (log.isDebugEnabled()) {              log.debug("Created connection " + conn.getRealHashCode() + ".");            }          } else {            // Cannot create new connection            PooledConnection oldestActiveConnection = state.activeConnections.get(0);            long longestCheckoutTime = oldestActiveConnection.getCheckoutTime();            if (longestCheckoutTime > poolMaximumCheckoutTime) {              // Can claim overdue connection              state.claimedOverdueConnectionCount++;              state.accumulatedCheckoutTimeOfOverdueConnections += longestCheckoutTime;              state.accumulatedCheckoutTime += longestCheckoutTime;              state.activeConnections.remove(oldestActiveConnection);              if (!oldestActiveConnection.getRealConnection().getAutoCommit()) {                oldestActiveConnection.getRealConnection().rollback();              }              conn = new PooledConnection(oldestActiveConnection.getRealConnection(), this);              oldestActiveConnection.invalidate();              if (log.isDebugEnabled()) {                log.debug("Claimed overdue connection " + conn.getRealHashCode() + ".");              }            } else {              // Must wait              try {                if (!countedWait) {                  state.hadToWaitCount++;                  countedWait = true;                }                if (log.isDebugEnabled()) {                  log.debug("Waiting as long as " + poolTimeToWait + " milliseconds for connection.");                }                long wt = System.currentTimeMillis();                state.wait(poolTimeToWait);                state.accumulatedWaitTime += System.currentTimeMillis() - wt;              } catch (InterruptedException e) {                break;              }            }          }        }        if (conn != null) {          if (conn.isValid()) {            if (!conn.getRealConnection().getAutoCommit()) {              conn.getRealConnection().rollback();            }            conn.setConnectionTypeCode(assembleConnectionTypeCode(dataSource.getUrl(), username, password));            conn.setCheckoutTimestamp(System.currentTimeMillis());            conn.setLastUsedTimestamp(System.currentTimeMillis());            state.activeConnections.add(conn);            state.requestCount++;            state.accumulatedRequestTime += System.currentTimeMillis() - t;          } else {            if (log.isDebugEnabled()) {              log.debug("A bad connection (" + conn.getRealHashCode() + ") was returned from the pool, getting another connection.");            }            state.badConnectionCount++;            localBadConnectionCount++;            conn = null;            if (localBadConnectionCount > (poolMaximumIdleConnections + 3)) {              if (log.isDebugEnabled()) {                log.debug("PooledDataSource: Could not get a good connection to the database.");              }              throw new SQLException("PooledDataSource: Could not get a good connection to the database.");            }          }        }      }    }    if (conn == null) {      if (log.isDebugEnabled()) {        log.debug("PooledDataSource: Unknown severe error condition.  The connection pool returned a null connection.");      }      throw new SQLException("PooledDataSource: Unknown severe error condition.  The connection pool returned a null connection.");    }    return conn;  }

 

转载地址:http://bwgfl.baihongyu.com/

你可能感兴趣的文章
《精通ArcGIS Server 应用与开发》——2.2 ArcGIS Server架构
查看>>
《UNIX网络编程 卷1:套接字联网API(第3版)》——2.10 TCP端口号与并发服务器...
查看>>
Centrifugo —— 用 Golang 实现的实时消息通信平台
查看>>
《善用佳软:高效能人士的软件应用之道》一2.6 小工具之计算器
查看>>
《Web前端工程师修炼之道(原书第4版)》——关于浏览器
查看>>
关于CKEditor4.5.6的使用,自定义toolbar配置,上传图片案例(SpringMVC+MyBatis案例),自定义行高,去编辑器的中内容,将编辑器中内容设置到指定的位置等...
查看>>
Ejoy2D —— 来自云风的开源游戏图形引擎
查看>>
Linux主机肉鸡木马minerd导致CPU跑满
查看>>
Organelle —— 支持编程的智能音频设备,能玩!
查看>>
《非常网管:网络管理从入门到精通(修订版)》——1.3 ISO/OSI参考模型
查看>>
自制“神器”,2017 最新 Web 开发者成长路线图
查看>>
Dotty —— Scala 的下一代编译器和技术研究平台
查看>>
phpMyAdmin 4.0.0-rc4 发布
查看>>
lygit 1.0.0 发布,基于 ThinkPHP 的 git 控制系统
查看>>
《大数据算法》一第2章 时间亚线性算法 
查看>>
《玩赚比特币》——导读
查看>>
《伟大的计算原理》一第2章
查看>>
用好DataV可视化大屏,紧抓商机,为“云供应链”做精细运营
查看>>
grep 的开源替代品 Go sift
查看>>
《嵌入式 Linux C 语言应用程序设计(修订版)》——2.3 嵌入式Linux编译器GCC的使用...
查看>>