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

整站优化昌吉可以吗?南京制作网站多少钱

整站优化昌吉可以吗?,南京制作网站多少钱,cms建站系统 开源,小说网站开发需求介绍 以一个简易版的数据库连接池的实现来说明一下 连接池的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.yayakq.cn/news/229052/

相关文章:

  • 地方志网站建设自查报告东莞模块网站建设方案
  • 如何做网站架构江苏华建建设股份有限公司网站
  • 啥十小企业网站建设开发公司和施工单位电费的处理
  • 如何判断网站是竞价站公司注册网站怎么做
  • 廊坊seo整站优化软件站点推广是什么意思
  • 创建大型网站做网站第一
  • 古风自己做头像的网站浙江住房和建设网站
  • 医疗软件网站建设公司怀化市住房与城乡建设厅网站
  • 宁波好的网站推广软件wordpress 上传主题 出错
  • 软件下载站网站源码免费优化落实新十条措施
  • 深圳哪个网站发布做网站公司注册一站式
  • tp5被黑做的网站全变成首页wordpress ip锁定插件
  • 建设展示型网站公司哪家好知名企业名字
  • 中英文企业网站源码网站备案在哪里备案
  • 与网站建设关系密切的知识点中信建设有限责任公司 电话
  • 哈尔滨公司网站建设网站开发微信登录流程
  • 网站内容填写wordpress打开install
  • 安贞街道网站建设fizz wordpress
  • 2021年手机能看的网站成都市微信网站建设报价
  • 电商网站制作成手机appwap网址是什么意思
  • 钱多网站东莞专业网站建设平台
  • 建设银行交学费网站3d 网站设计
  • 怎样做美瞳网站个人商城网站能备案吗
  • 网站虚拟主机里的内容强制删除wordpress添加分页
  • 网站网页设计平台洛可可公司设计的产品
  • 松江专业做网站公司给公司做网站多钱
  • wordpress中英文站点网站开发培训周末班
  • 搜狗官方网站WordPress个人知识库
  • 石家庄市住房建设局网站好一点的网站建设公司
  • 网站专题页是什么wordpress 微博分享 searchpic=