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

建立自己网站要多少钱友情链接交易平台源码

建立自己网站要多少钱,友情链接交易平台源码,能买源码的网站有哪些,邵阳网站建设设计介绍 以一个简易版的数据库连接池的实现来说明一下 连接池的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.dt0577.cn/news/34067.html

相关文章:

  • 网站重新备案需要多长时间seo臻系统
  • 老版本网站开发工具宁波seo外包费用
  • 网站创建网站平台推广方案模板
  • 丽江市建设局官方网站百度付费推广有几种方式
  • seo网站结构图互联网媒体推广
  • 今日新闻摘抄二十条网站排名优化培训哪家好
  • 贵州住房和建设厅网站武汉大学人民医院洪山院区
  • 简约网站建设公司免费的推广网站
  • 做网站最适合用多大的图片品牌seo如何优化
  • 服务器安装完面板怎么做网站网站发布与推广怎么写
  • 网站建设网站建设哪里有百度网址大全手机版
  • 在线生成logo设计武汉seo推广
  • 企业做网站报价百度学术论文查重入口
  • 宝塔自助建站源码网站设计论文
  • 上海地产网站建设上海网络推广招聘
  • 厦门做网页网站的公司如何在百度做推广
  • 网站建设合同验收阿里巴巴运营
  • 杭州的服装网站建设网络广告推广方式
  • 网站建设咨询公司怎样做好服务营销
  • 绵阳网络公司网站建设目前最靠谱的推广平台
  • 数字媒体应用 网站开发全网优化推广
  • 武汉政鑫建设有限公司网站企业网站建设步骤
  • 江西建设网官方网站站长统计app进入网址新版小猪
  • 外贸网站建设维护站长工具seo下载
  • 有哪些可以做兼职翻译的网站关键词优化seo优化排名
  • 昆山网站建设哪家便宜拓客软件
  • 做网站时背景音乐seo优化关键词
  • 方向专业网站制作咨询厦门网站seo外包
  • o2o电子商务网站建设南宁seo渠道哪家好
  • 怎么查网站是哪家公司做的十大少儿编程教育品牌