@@ -36,9 +36,17 @@ public class PropertyUtils {
3636 private final String propertiesFilePath ;
3737
3838 public static final Integer DEFAULT_TAINT_TO_STRING_CHAR_LIMIT = 1024 ;
39+ public static final Integer DEFAULT_POOL_CAPACITY = 4096 ;
40+ public static final Integer DEFAULT_POOL_SIZE = 0 ;
41+ public static final Integer DEFAULT_POOL_MAX_SIZE = 10 ;
42+ public static final Integer DEFAULT_POOL_KEEPALIVE = 10 ;
3943
4044 // 污点转换为字符串的时候字符数长度限制
4145 private Integer taintToStringCharLimit = DEFAULT_TAINT_TO_STRING_CHAR_LIMIT ;
46+ private Integer poolCapacity ;
47+ private Integer poolSize ;
48+ private Integer poolMaxSize ;
49+ private Integer poolKeepalive ;
4250
4351 public static PropertyUtils getInstance (String propertiesFilePath ) throws DongTaiPropertyConfigException , DongTaiEnvConfigException {
4452 if (null == instance ) {
@@ -78,7 +86,7 @@ private void init() throws DongTaiPropertyConfigException, DongTaiEnvConfigExcep
7886
7987 // 初始化一些参数
8088 this .initTaintToStringCharLimit ();
81-
89+ this . initPool ();
8290 }
8391
8492 public static String getTmpDir () {
@@ -244,6 +252,34 @@ public static Integer getTaintToStringCharLimit() {
244252 return instance .taintToStringCharLimit ;
245253 }
246254
255+ public Integer getPoolCapacity () {
256+ if (instance == null ) {
257+ return DEFAULT_POOL_CAPACITY ;
258+ }
259+ return instance .poolCapacity ;
260+ }
261+
262+ public Integer getPoolSize () {
263+ if (instance == null ) {
264+ return DEFAULT_POOL_SIZE ;
265+ }
266+ return instance .poolSize ;
267+ }
268+
269+ public Integer getPoolMaxSize () {
270+ if (instance == null ) {
271+ return DEFAULT_POOL_MAX_SIZE ;
272+ }
273+ return instance .poolMaxSize ;
274+ }
275+
276+ public Integer getPoolKeepalive () {
277+ if (instance == null ) {
278+ return DEFAULT_POOL_KEEPALIVE ;
279+ }
280+ return instance .poolKeepalive ;
281+ }
282+
247283 /**
248284 * 初始化taintToStringCharLimit参数的值
249285 *
@@ -274,6 +310,36 @@ public void initTaintToStringCharLimit() throws DongTaiPropertyConfigException,
274310
275311 }
276312
313+ private void initPool () throws DongTaiPropertyConfigException , DongTaiEnvConfigException {
314+ this .poolCapacity = parseAndSetProperty (PropertyConstant .PROPERTY_POOL_CAPACITY , DEFAULT_POOL_CAPACITY );
315+ this .poolSize = parseAndSetProperty (PropertyConstant .PROPERTY_POOL_SIZE , DEFAULT_POOL_SIZE );
316+ this .poolMaxSize = parseAndSetProperty (PropertyConstant .PROPERTY_POOL_MAX_SIZE , DEFAULT_POOL_MAX_SIZE );
317+ this .poolKeepalive = parseAndSetProperty (PropertyConstant .PROPERTY_POOL_KEEPALIVE , DEFAULT_POOL_KEEPALIVE );
318+ }
319+
320+ private Integer parseAndSetProperty (String propertyKey ,Integer defaultValue ) throws DongTaiPropertyConfigException , DongTaiEnvConfigException {
321+ String propertyStr = cfg .getProperty (propertyKey );
322+ Integer value = defaultValue ;
323+ if (!StringUtils .isBlank (propertyStr )) {
324+ value = Integer .parseInt (propertyStr .trim ());
325+ if (value <= 0 ) {
326+ throw new DongTaiPropertyConfigException ("The value of parameter " + propertyKey
327+ + " value " + propertyStr + " in your configuration file " + this .propertiesFilePath + " is illegal, such as passing a number greater than 1" );
328+ }
329+ }
330+
331+ // 2. 然后从环境变量中读取
332+ propertyStr = System .getProperty (propertyKey );
333+ if (!StringUtils .isBlank (propertyStr )) {
334+ value = Integer .parseInt (propertyStr .trim ());
335+ if (value <= 0 ) {
336+ throw new DongTaiEnvConfigException ("The value of this parameter " + propertyKey
337+ + " value " + propertyStr + " in your environment variables is illegal, such as passing an number greater than 1" );
338+ }
339+ }
340+ return value ;
341+ }
342+
277343 /**
278344 * Property文件配置错误
279345 */
0 commit comments