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

网站建设有利于做监控的有哪些网站

网站建设有利于,做监控的有哪些网站,公众号开发哪家好,查网站ip地址介绍 以一个简易版的数据库连接池的实现来说明一下 连接池的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/638028/

相关文章:

  • 装潢公司网站模块后台管理网站开发
  • 新泰网站开发中国排名前十的广告公司
  • 交易类网站建设费用百度录取线我的wordpress
  • nas云存储做视频网站动态交互图表制作
  • 可以用来做简单的网络验证的网站推进网站建设工作计划
  • 私人找人做网站手机免费图片制作软件
  • 建筑网名windows优化软件
  • 新网站怎么做谷歌推广呢柳州市建设工程质量安全监督管理处网站
  • 网站开发成本如何账务处理房在线房产中介管理系统
  • 旅游订票网站开发黑龙江省瑞驰建设集团网站
  • 站长友情链接指数分布的期望和方差
  • 昆明网站建站网站源码分享
  • 临沂住房和城乡建设局网站打不开18款禁用软件app网站入口
  • flash网站怎么制作成都住建局官网房源
  • 简述网站开发工作流程官方网站建设调研报告
  • 如何用自己的域名做网站哪家公司搭建网站
  • 网站底部导航设置芙蓉区网站建设
  • 网络设置的网站免费网站推广优化
  • 深圳网站seo教程wordpress如何抓取
  • 网站安装源码西安网站制作有限公司
  • 信息手机网站模板昆山网站建设河北
  • 电商网站的建设背景图片青岛谁优化网站做的好
  • 东莞大型网站建设公司wordpress放弃php
  • 中山网站seo优化县级部门和乡镇不能建网站建设
  • 任务网站(做任务学技能的)建材企业网站推广
  • 大连建设工程信息网站网站建设工作落实情况
  • 检测网站开发语言工具大连云建站模板
  • 抚州市城乡建设局网站九江哪家网站建设公司好
  • 怎么自己创建网站免费网站建设补充协议模板
  • 网站页脚设计建设网站上申请劳务资质