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

环保网站主题手机网站尺寸大小

环保网站主题,手机网站尺寸大小,东莞市电商网站建设,完美代码网站timeout变量似乎不对应于连接空闲的时间#xff0c;而是对应于池等待返回新连接或抛出异常的时间(我看了一下这个源代码 #xff0c;不知道是不是已是最新)。 我认为跟踪“空闲”连接是相当困难的#xff0c;因为在这种情况下“空闲”真正意味着什么#xff1f; 您可能希望…timeout变量似乎不对应于连接空闲的时间而是对应于池等待返回新连接或抛出异常的时间(我看了一下这个源代码 不知道是不是已是最新)。 我认为跟踪“空闲”连接是相当困难的因为在这种情况下“空闲”真正意味着什么 您可能希望获得连接以供以后使用。 所以我想说连接池知道你完成连接的唯一安全方法就是调用close() 。如果你担心开发团队忘记在他们的代码中调用close() 有一种技术我在下面描述并且我过去曾经使用过(在我的例子中我们想要跟踪未闭合的InputStream但概念是相同)。免责声明我假设连接仅在单个请求期间使用并且在连续请求期间不跨越。 在后一种情况下您无法使用下面的解决方案。您的连接池实现似乎已经使用了与我在下面描述的技术类似的技术(即它已经包装了连接)所以我不可能知道这是否适用于您的情况。 我没有测试下面的代码我只是用它来描述这个概念。请仅在您的开发环境中使用它。 在生产中您应该确信您的代码已经过测试并且行为正确。如上所述主要思想是我们有一个中心位置(连接池)我们从中获取资源(连接)我们希望跟踪我们的代码是否释放了这些资源。 我们可以使用一个Web Filter 它使用一个ThreadLocal对象来跟踪请求期间使用的连接。 我将此类命名为TrackingFilter 跟踪资源的对象是Tracker类。public class TrackingFilter implements Filter {Overridepublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {Tracker.start();try {chain.doFilter(request, response);} finally {Tracker.stop();}}...}为了使Tracker能够跟踪连接每次使用getConnection()获取连接时以及每次使用close()调用关闭连接时都需要通知它。 为了能够以对代码的其余部分透明的方式执行此操作我们需要包装ConnectionPool和返回的Connection对象。 您的代码应该返回新的TrackingConnectionPool而不是原始池(我假设访问连接池的方式是在一个地方)。 这个新池将依次包装它提供的每个Connection 作为TrackableConnection 。 TrackableConnection是知道如何在创建和关闭时通知我们的Tracker的对象。当您在请求结束时调用Tracker.stop()时它将报告尚未调用close()所有连接。 由于这是一个按请求操作您将只识别错误操作(即在“创建新产品”功能期间)然后希望您能够跟踪那些保留打开连接并修复它们的查询。您可以在下面找到TrackingConnectionPool TrackableConnection和Tracker类的代码和注释。 为简洁起见遗漏了代表方法。 我希望有所帮助。注意对于包装器使用自动IDE功能(如Eclipse的“生成委托方法”)否则这将是一个耗时且容易出错的任务。//------------- Pool CreationConnectionPool original new ConnectionPool(String dbpoolName, ...);TrackingConnectionPool trackingCP new TrackingConnectionPool(original);// ... or without creating the ConnectionPool yourselfTrackingConnectionPool trackingCP new TrackingConnectionPool(dbpoolName, ...);// store the reference to the trackingCP instead of the original//------------- TrackingConnectionPoolpublic class TrackingConnectionPool extends ConnectionPool {private ConnectionPool originalPool; // reference to the original pool// Wrap all available ConnectionPool constructors like thispublic TrackingConnectionPool(String dbpoolName, ...) {originalPool new ConnectionPool(dbpoolName, ...);}// ... or use this convenient constructor after you create a pool manuallypublic TrackingConnectionPool(ConnectionPool pool) {this.originalPool pool;}Overridepublic Connection getConnection() throws SQLException {Connection con originalPool.getConnection();return new TrackableConnection(con); // wrap the connections with our own wrapper}Overridepublic Connection getConnection(long timeout) throws SQLException {Connection con originalPool.getConnection(timeout);return new TrackableConnection(con); // wrap the connections with our own wrapper}// for all the rest public methods of ConnectionPool and its parent just delegate to the originalOverridepublic void setCaching(boolean b) {originalPool.setCaching(b);}...}//------------- TrackableConnectionpublic class TrackableConnection implements Connection, Tracker.Trackable {private Connection originalConnection;private boolean released false;public TrackableConnection(Connection con) {this.originalConnection con;Tracker.resourceAquired(this); // notify tracker that this resource is aquired}// Trackable interfaceOverridepublic boolean isReleased() {return this.released;}// Note: this method will be called by Tracker class (if needed). Do not invoke manuallyOverridepublic void release() {if (!released) {try {// attempt to close the connectionoriginalConnection.close();this.released true;} catch(SQLException e) {throw new RuntimeException(e);}}}// Connection interfaceOverridepublic void close() throws SQLException {originalConnection.close();this.released true;Tracker.resourceReleased(this); // notify tracker that this resource is released}// rest of the methods just delegate to the original connectionOverridepublic Statement createStatement() throws SQLException {return originalConnection.createStatement();}....}//------------- Trackerpublic class Tracker {// Create a single object per threadprivate static final ThreadLocal _tracker new ThreadLocal() {Overrideprotected Tracker initialValue() {return new Tracker();};};public interface Trackable {boolean isReleased();void release();}// Stores all the resources that are used during the thread.// When a resource is used a call should be made to resourceAquired()// Similarly when we are done with the resource a call should be made to resourceReleased()private Map monitoredResources new HashMap();// Call this at the start of each thread. It is important to clear the map// because you cant know if the server reuses this threadpublic static void start() {Tracker monitor _tracker.get();monitor.monitoredResources.clear();}// Call this at the end of each thread. If all resources have been released// the map should be empty. If it isnt then someone, somewhere forgot to release the resource// A warning is issued and the resource is released.public static void stop() {Tracker monitor _tracker.get();if ( !monitor.monitoredResources.isEmpty() ) {// there are resources that have not been released. Issue a warning and release each one of themfor (Iterator it monitor.monitoredResources.keySet().iterator(); it.hasNext();) {Trackable resource it.next();if (!resource.isReleased()) {System.out.println(WARNING: resource resource has not been released. Releasing it now.);resource.release();} else {System.out.println(Trackable resource is released but is still under monitoring. Perhaps you forgot to call resourceReleased()?);}}monitor.monitoredResources.clear();}}// Call this when a new resource is acquired i.e. you a get a connection from the poolpublic static void resourceAquired(Trackable resource) {Tracker monitor _tracker.get();monitor.monitoredResources.put(resource, resource);}// Call this when the resource is releasedpublic static void resourceReleased(Trackable resource) {Tracker monitor _tracker.get();monitor.monitoredResources.remove(resource);}}
http://www.zqtcl.cn/news/964977/

相关文章:

  • 西宁网站建设优化东莞建网站公司案例
  • 建设网站iss手工活接单在家做有正规网站吗
  • 六安做网站的公司专门建立网站的公司吗
  • 西昌市建设工程管理局网站wordpress主题知更
  • 企业网站如何上存青岛做外贸网站哪家好
  • 保定网站建设冀icp备织梦设置中英文网站
  • 烟台市建设工程检测站网站妖姬直播
  • 式网站西安网页搭建
  • 百度云虚拟主机如何建设网站四川建设人员信息查询
  • 浅谈学校网站建设html5网页制作代码成品
  • 网站在当地做宣传郑州高端设计公司
  • 一级a做爰网站微网站建设平台
  • 网站建设 中广州网站建设+致茂
  • 常德车管所网站工作微信管理系统
  • 什么软件可以做dj视频网站做的好的装修公司网站
  • 网站维护的内容和步骤如何建设像艺龙一样网站
  • 外国人做的学汉字网站公司网页需要哪些内容
  • 网站做缓存企业营销型网站的内容
  • 免费带后台的网站模板wordpress vr主题公园
  • 美丽乡村 网站建设wordpress分页工具栏
  • 卡盟网站是怎么建设的产品开发设计
  • 第一免费营销型网站一起做网店17
  • 高端学校网站建设做网站是怎么赚钱的
  • 哪里可以找人做网站在服务器上中的asp网站后台能输入帐号无法进入
  • 怎么网站关键词语有哪些
  • 网站建设 维护费用环球易购招聘网站建设
  • 怎么做网站官方电话手机应用开发平台
  • 济南企业免费建站剪辑视频怎么学
  • 手表网站免费设计上海做网站制作
  • 深圳网站seo优化课程设计做淘宝网站的目的