当前位置: 首页 > news >正文

专做电子产品评测的网站百度搜索seo优化技巧

专做电子产品评测的网站,百度搜索seo优化技巧,网站建设与更新,校园互动网站建设介绍 以一个简易版的数据库连接池的实现来说明一下 连接池的connection以队列来管理 getConnection的时候,如果队列中connection个数小于50,且暂时无可用的connection(个数为0或者peek看下头部需要先出那个元素还处于不可用状态)…

介绍

以一个简易版的数据库连接池的实现来说明一下
连接池的connection以队列来管理
getConnection的时候,如果队列中connection个数小于50,且暂时无可用的connection(个数为0或者peek看下头部需要先出那个元素还处于不可用状态),就新建连接并建立连接,开始一直新建到50个connection,就是_currentPoolSize =50
如果队列中connection个数大于等于50,且暂时无可用的connection(个数为0或者peek看下头部需要先出那个元素还处于不可用状态),就等着Monitor.Wait(_connectionPoolQueueLock)

returnConnection的时候,使用Monitor.Pulse(_connectionPoolQueueLock) 随机通知一个wait的线程可以继续getConnection了

using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using Mono.Data.Sqlite;namespace demo.unity.sqlite
{public class SQLiteConnectionManager{private Queue<Tuple<SqliteConnection, DateTime>> _connectionPoolQueue;private object _connectionPoolQueueLock = new object();private const int maxPoolSize = 50;private volatile bool _disposed;private int _currentPoolSize;private readonly System.Timers.Timer _cleanupTimer = new System.Timers.Timer(10 * 60 * 1000);public SQLiteConnectionManager(){_connectionPoolQueue = new Queue<Tuple<SqliteConnection, DateTime>>(maxPoolSize);_cleanupTimer.Elapsed += _cleanupTimerElapsed;_cleanupTimer.AutoReset = true;_cleanupTimer.Start();}private void _cleanupTimerElapsed(object sender, System.Timers.ElapsedEventArgs e){lock (_connectionPoolQueueLock){while (_connectionPoolQueue.Count > 0 && (DateTime.UtcNow - _connectionPoolQueue.Peek().Item2).TotalMinutes > 15){var tup = _connectionPoolQueue.Dequeue();tup.Item1.Dispose();_currentPoolSize--;}}}private SqliteConnection _createNewConnection(SqliteConnectionStringBuilder builder){var connection = new SqliteConnection(builder.ConnectionString);connection.Open();return connection;}public SqliteConnection getConnection(SqliteConnectionStringBuilder builder){lock (_connectionPoolQueueLock){// count == 0 or queue.peek no use connectionwhile (_connectionPoolQueue.Count == 0  || _connectionPoolQueue.Peek().Item1.State != ConnectionState.Open){if (_disposed){throw new ObjectDisposedException("The DB connection pool is is already disposed");}if (_currentPoolSize < maxPoolSize){// create and open connectionvar connection = _createNewConnection(builder);_connectionPoolQueue.Enqueue( new Tuple<SqliteConnection, DateTime>(connection, DateTime.UtcNow));_currentPoolSize++;}else{Monitor.Wait(_connectionPoolQueueLock);}}return _connectionPoolQueue.Dequeue().Item1;}}public void returnConnection(SqliteConnection connection){if (connection == null){return;}lock (_connectionPoolQueueLock){_connectionPoolQueue.Enqueue(new Tuple<SqliteConnection, DateTime>(connection, DateTime.UtcNow));Monitor.Pulse(_connectionPoolQueueLock);}}public void dispose(){lock (_connectionPoolQueueLock){_disposed = true;while (_connectionPoolQueue.Count > 0){var tup  = _connectionPoolQueue.Dequeue();tup.Item1?.Dispose();_currentPoolSize--;}// wake up any waiting threadsMonitor.PulseAll(_connectionPoolQueueLock);}_cleanupTimer.Stop();_cleanupTimer.Dispose();}}
}
http://www.zhongyajixie.com/news/5475.html

相关文章:

  • 买好域名后怎么做网站seo免费培训视频
  • 国外做的比较好的网站关键词林俊杰的寓意
  • dedecms 手机网站模板b2b免费推广平台
  • php做的商城网站必备功能百度官方入口
  • 盘锦网站建设热线电话优化关键词排名优化公司
  • wordpress广告图片代码站长工具seo查询5g5g
  • 企业网站设计域名是什么 有什么用
  • 做相亲网站需要什么流程查关键词排名网
  • 网站空间服务器费用如何做品牌宣传与推广
  • 做免费外贸网站自媒体是如何赚钱的
  • 途牛企业网站建设seo课培训
  • 政府网站建设先进个人先进事迹网络营销专业是干嘛的
  • 网站域名301设置百度搜索广告价格
  • 新媒体与网站建设seo排名助手
  • 学做网站论坛会员账户百度竞价托管哪家好
  • 做管理培训的网站有什么怎样做好网络营销推广
  • 6网站建设做网站秘密入口3秒自动进入
  • 福州营销型网站建设价格百度快照不更新怎么办
  • 建筑交流平台windows优化大师有必要安装吗
  • 企业网站的特征无锡营销型网站建站
  • 广州 网站 设计近期网络营销的热点事件
  • 日照外贸网站建设网站推广排名教程
  • ps怎样做网站设计百度推广代理赚钱
  • 四川做网站设计的公司网络营销心得体会800字
  • logo设计在线生成 免费武汉企业seo推广
  • 搭建好网站生情好域名后怎么做网址检测
  • 用dw做网站的基本步骤如何优化网页
  • c语言做的网站湖南百度seo排名点击软件
  • 珠海公司网站制作公网络营销主要有哪些特点
  • 湖北建设信息网站免费域名解析