资源描述:
《连接池的基本工作原理(the basic working principle of the connection pool)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、连接池的基本工作原理(Thebasicworkingprincipleoftheconnectionpool)1.BasicconceptsandprinciplesAscanbeseenfromtheaboveanalysis,therootoftheproblemistheinefficientmanagementofdatabaseconnectionresources.Weknowthatthereisawell-knowndesignpatternforsharedresources:theResourcePool.Themodelisdesigned
2、toaddressthefrequentallocationofresourcesandtheproblemscausedbyrelease.Tosolvetheaboveproblems,databaseconnectionpoolingtechnologycanbeused.Thebasicideaofthedatabaseconnectionpoolistobuildabufferpoolforthedatabaseconnection".Acertainnumberofconnectionsareplacedinthebufferpoolinadvanc
3、e.Whenyouneedtobuildadatabaseconnection,youjusttakeonefromthebufferpoolandputitbackafteryou'vefinishedusingit.Wecanpreventthesystemfromendlessdatabaseconnectionsbysettingthemaximumnumberofconnectionsintheconnectionpool.Moreimportantly,wecanmonitorthenumberofconnectionstothedatabaseth
4、roughtheconnectionpoolmanagementmechanism,whichprovidesthebasisforsystemdevelopment,testing,andperformancetuning.2,theservercomeswiththeconnectionpoolThereisnoconnectionpoolmethodavailableinJDBC'sAPI.SomelargeWEBapplicationservers,suchasBEA'sWebLogicandIBM'sWebSphere,providetheconnec
5、tionpoolmechanism,butmusthavetheirthirdprivateclassmethodsthatsupporttheusageoftheconnectionpool.Analysisofkeyproblemsinconnectionpool1,concurrentproblemsInorderforconnectivitymanagementservicestobeofmaximumversatility,multithreadedenvironments,namelyconcurrencyproblems,mustbeconside
6、red.Thisproblemisrelativelygoodtosolve,becausetheJavalanguageitselfprovidessupportforconcurrentmanagement,usingthesynchronizedkeywordtoensurethatthethreadissynchronized.Themethodofuseistodirectlyaddasynchronizedkeywordtotheclassmethod,suchas:Public,synchronized,Connection,getConnecti
7、on()2,multidatabaseserverandmultiuserForlargeenterpriseapplications,youoftenneedtoconnectdifferentdatabases(suchasOracleandSybase)atthesametime.Howdoyouconnecttodifferentdatabases?Weadoptthestrategyisdesignedwithasinglemodeconnectionpoolmanagement,theonlyinstanceiscreatedintheconnect
8、ionpoolmanag