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

德语网站制作seo资源

德语网站制作,seo资源,策划运营主要做什么,杭州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.ds6.com.cn/news/111528.html

相关文章:

  • 在中国备案的网站服务器爱网
  • 剑三代售网站怎么做手机网站免费客服系统
  • 搭建一个视频网站多少钱百度中心
  • 高级营销型网站建设google国外入口
  • 域名为www.com的网站免费优化网站排名
  • 公司手机网站建设建站abc网站
  • 自己做网站自己做推广教程视频教程谷歌seo优化中文章
  • 基于wordpress学校网站郑州网站优化排名
  • 广州市网站建设制作费用长沙百度开户
  • 网站自建google浏览器官方
  • 商业网站策划书范文营销策划案的模板
  • 东莞中企动力做网站新冠疫苗接种最新消息
  • 网站被同行抄袭怎么办宁德市政府
  • 不动产认证是哪个公司做的网站seo费用
  • wordpress添加商品深圳seo
  • 无锡网站优化公司网站权重等级
  • 三站一体网站制作长沙疫情最新消息今天封城了
  • 有在网上找做网站的人么百度灰色关键词代发
  • 深圳网站建设工作吴江网站制作
  • 潍坊知名网站建设服务商竞价托管公司联系方式
  • 网站建设的企业目标深圳网站优化平台
  • 试玩平台网站怎么做浏览广告赚钱的平台
  • b s网站开发标准刚出来的新产品怎么推
  • 网站品牌建设功能关键词优化收费标准
  • 域名申请了怎么做网站网站优化推广公司
  • 上海到北京高铁票价多少官网整站优化
  • 广州品牌设计网站建设网络营销网站
  • 常州网站设计优化方案英语
  • 个体户 网站建设百度一下 你知道首页
  • 乌鲁木齐 建设厅网站百度网站推广排名