<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Dev Zone
    偏執(zhí)狂才能生存,人生/事業(yè)的路上需要再堅(jiān)持一下
    但是又怎么說得清堅(jiān)持的結(jié)果,道得盡堅(jiān)持的含義
    1。XAPool是如何wrap jdbc driver返回的PreparedStatement的。
    以下是StandardConnectionHandler中的checkPreparedCache代碼片斷
    ????synchronized?PreparedStatement?checkPreparedCache(
    ????????String?sql,
    ????????
    int?type,
    ????????
    int?concurrency)
    ????????throws?SQLException?{
    ????????log.debug(
    ????????????
    "StandardConnectionHandle:checkPreparedCache?sql='"?+?sql?+?"'");
    ????????PreparedStatement?ret?
    =?null;?//?the?return?value
    ????????
    //?NOTE?-?We?include?the?Connection?in?the?lookup?key.?This?has?no
    ????????
    //?effect?here?but?is?needed?by?StandardXAConnection?where?the?the?physical
    ????????
    //?Connection?used?can?vary?over?time?depending?on?the?global?transaction.
    ????????String?lookupKey?=?sql?+?type?+?concurrency;
    ????????
    //?used?to?lookup?statements
    ????????if?(preparedStatementCache?!=?null)?{
    ????????????Object?obj?
    =?preparedStatementCache.get(lookupKey);
    ????????????
    //?see?if?there's?a?PreparedStatement?already
    ????????????if?(obj?!=?null)?{?//?if?there?is
    ????????????????ret?=?(PreparedStatement)?obj;?//?use?as?return?value
    ????????????????try?{
    ????????????????????ret.clearParameters();?
    //?make?it?look?like?new
    ????????????????}?catch?(SQLException?e)?{
    ????????????????????
    //?Bad?statement,?so?we?have?to?create?a?new?one
    ????????????????????ret?=?createPreparedStatement(sql,?type,?concurrency);
    ????????????????}

    ????????????????preparedStatementCache.remove(lookupKey);
    ????????????????
    //?make?sure?it?cannot?be?re-used
    ????????????????inUse.put(lookupKey,?ret);
    ????????????????
    //?make?sure?it?gets?reused?by?later?delegates
    ????????????}?else?{?//?no?PreparedStatement?ready
    ????????????????ret?=?createPreparedStatement(sql,?type,?concurrency);
    ????????????????inUse.put(lookupKey,?ret);
    ????????????????
    //?will?get?saved?in?prepared?statement?cache
    ????????????}
    ????????}?
    else?{
    ????????????ret?
    =?createPreparedStatement(sql,?type,?concurrency);
    ????????}
    ????????
    //?We?don't?actually?give?the?application?a?real?PreparedStatement.?Instead
    ????????
    //?they?get?a?StandardPreparedStatement?that?delegates?everything?except
    ????????
    //?PreparedStatement.close();

    ????????ret?
    =?new?StandardPreparedStatement(this,?ret,?lookupKey);
    ????????
    return?ret;
    ????}

    2。StandardPreparedStatement的Close方法代碼片斷
    ????public?void?close()?throws?SQLException?{
    ????????
    //?Note?no?check?for?already?closed?-?some?servers?make?mistakes
    ????????closed?=?true;
    ????????
    if?(con.preparedStmtCacheSize?==?0)?{
    ????????????
    //?no?cache,?so?we?just?close
    ????????????if?(ps?!=?null)?{
    ????????????????ps.close();
    ????????????}
    ????????}?
    else?{
    ????????????con.returnToCache(key);
    ????????????
    //?return?the?underlying?statement?to?the?cache
    ????????}
    ????}

    3。xapool StandardPoolDataSource的getConnection 原理:
    ???? StandardPoolDataSource.getConnection --> GenericPool.checkOut-->StandardPoolDataSource.create -->StandardPoolDataSource.getPooledConnection:返回StandardPooledConnection。
    ?
    ???? StandardPooledConnection通過StandardDataSource.getConnection獲取jdbc driver返回的connection(physical connection),然后通過工廠方法newConnectionHandle采用StandardConnectionHandler對(duì)該connection進(jìn)行包裝。StandardConnectionHandler對(duì)PreparedStatement進(jìn)行重新包裝和Cache,對(duì)connection.close進(jìn)行了控制。
    ?
    4。xapool StandardXAPoolDataSource的getConnection的原理:
    ?? StandardXAPoolDataSource.getConnection -->StandardPoolDataSource.getConnection-->StandardXAPoolDataSource.create -->XADataSource.getXAConnection -->StandardXADatasource.getXAConnection:返回StandardXAConnection。
    ??? StandardXAConnection通過StandardDataSource.getConnection獲取jdbc driver返回的connection(physical connection),然后通過工廠方法newConnectionHandle采用StandardXAConnectionHandle對(duì)該connection進(jìn)行包裝。StandardXAConnectionHandler繼承自StandardConnectionHandler。
    ?
    5。xapool從StandardPoolDataSource獲取的 Connection的關(guān)閉原理。
    ?? StandardPooledConnection.close-->StandardConnectionHandler.close(設(shè)置closed=true,回收PreparedStatement)-->StandardPooledConnection.closeEvent-->StandardPoolDataSource.connectionClosed-->GenericPool.checkIn(返回連接池)
    ?
    6.xapool中對(duì)連接池進(jìn)行管理的類是GenericPool,該類的checkOut和checkIn方法分別完成連接獲取和連接回收功能。checkOut從unlocked池中獲取可用的連接,如果需要進(jìn)行檢查或者測(cè)試,然后返回;如果發(fā)現(xiàn)unlocked池中沒有連接,在連接數(shù)小于maxSize的時(shí)候調(diào)用PoolHelper的實(shí)現(xiàn)類創(chuàng)建連接,如果連接數(shù)已經(jīng)達(dá)到或者超過maxSize,調(diào)用wait使當(dāng)前進(jìn)程進(jìn)入等待狀態(tài)(等待期限和等待間隔可以設(shè)置),如果等待過程中其他線程釋放了connection返回可用的connection,否則異常:GenericPool:checkOut ERROR? impossible to obtain a new object from the pool
    posted on 2005-05-17 22:07 dev 閱讀(1815) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
     
    主站蜘蛛池模板: 久久国产精品免费一区| 亚洲色少妇熟女11p| 84pao强力永久免费高清| 亚洲成人高清在线| 美女视频黄.免费网址| 免费大片在线观看网站| 亚洲AV无码一区二区大桥未久| 最近中文字幕mv手机免费高清| 亚洲欧洲国产视频| 国产成人免费爽爽爽视频 | 2022久久国产精品免费热麻豆| 亚洲va在线va天堂va不卡下载| 中文字幕乱码一区二区免费| 久久精品国产亚洲AV麻豆王友容| 四虎影视成人永久免费观看视频 | 亚洲无砖砖区免费| 无人影院手机版在线观看免费| 亚洲中文字幕日本无线码| 精品免费久久久久国产一区 | 亚洲AV无码1区2区久久| 日本免费人成网ww555在线| 国产精品黄页在线播放免费| 久久久久亚洲Av无码专| 日韩欧美一区二区三区免费观看 | 又黄又大又爽免费视频| 国产精品永久免费| 亚洲精品视频在线免费| 女性无套免费网站在线看| 搜日本一区二区三区免费高清视频| 久久久久亚洲AV成人网| 最近免费中文字幕大全免费| 中国亚洲呦女专区| JLZZJLZZ亚洲乱熟无码| 中文字幕在线观看免费视频| 亚洲av无码专区在线观看亚| 狠狠综合久久综合88亚洲| 免费又黄又爽又猛大片午夜 | 亚洲精品国产成人专区| 在线看片免费不卡人成视频| 污网站在线免费观看| 亚洲色欲或者高潮影院|