# EasyTool **Repository Path**: w1418/EasyTool ## Basic Information - **Project Name**: EasyTool - **Description**: 常用工具集 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2018-11-09 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # [EasyTool](https://gitee.com/dunpo98k/EasyTool) #### 项目介绍 EasyTool - 常用工具集 #### 内容概览 1. RAR.ZIP包加密压缩,解压 2. 文件,字符串,日期,Class等常用数据对象处理工具类 3. 简单算法实现 4. 动态代理 5. 利用Freemarker动态生成word文档的样例 6. FTP连接池(基于commons-pool2实现) #### 特别说明 1. commons-pool2源码解析 - GenericObjectPool ```java public T borrowObject(long borrowMaxWaitMillis) throws Exception { this.assertOpen(); AbandonedConfig ac = this.abandonedConfig; if (ac != null && ac.getRemoveAbandonedOnBorrow() && this.getNumIdle() < 2 && this.getNumActive() > this.getMaxTotal() - 3) { this.removeAbandoned(ac); } PooledObject p = null; boolean blockWhenExhausted = this.getBlockWhenExhausted(); long waitTime = System.currentTimeMillis(); while(true) { boolean create; do { do { do { if (p != null) { this.updateStatsBorrow(p, System.currentTimeMillis() - waitTime); return p.getObject(); } create = false; p = (PooledObject)this.idleObjects.pollFirst(); if (p == null) { p = this.create(); if (p != null) { create = true; } } if (blockWhenExhausted) { if (p == null) { if (borrowMaxWaitMillis < 0L) { p = (PooledObject)this.idleObjects.takeFirst(); } else { p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, TimeUnit.MILLISECONDS); } } if (p == null) { throw new NoSuchElementException("Timeout waiting for idle object"); } } else if (p == null) { throw new NoSuchElementException("Pool exhausted"); } if (!p.allocate()) { p = null; } } while(p == null); try { this.factory.activateObject(p); } catch (Exception var13) { try { this.destroy(p); } catch (Exception var12) { ; } p = null; if (create) { NoSuchElementException nsee = new NoSuchElementException("Unable to activate object"); nsee.initCause(var13); throw nsee; } } } while(p == null); } while(!this.getTestOnBorrow() && (!create || !this.getTestOnCreate())); boolean validate = false; Throwable validationThrowable = null; try { validate = this.factory.validateObject(p); } catch (Throwable var15) { PoolUtils.checkRethrow(var15); validationThrowable = var15; } if (!validate) { try { this.destroy(p); this.destroyedByBorrowValidationCount.incrementAndGet(); } catch (Exception var14) { ; } p = null; if (create) { NoSuchElementException nsee = new NoSuchElementException("Unable to validate object"); nsee.initCause(validationThrowable); throw nsee; } } } } ```