@@ -36,9 +36,17 @@ public class PropertyUtils {
36
36
private final String propertiesFilePath ;
37
37
38
38
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 ;
39
43
40
44
// 污点转换为字符串的时候字符数长度限制
41
45
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 ;
42
50
43
51
public static PropertyUtils getInstance (String propertiesFilePath ) throws DongTaiPropertyConfigException , DongTaiEnvConfigException {
44
52
if (null == instance ) {
@@ -78,7 +86,7 @@ private void init() throws DongTaiPropertyConfigException, DongTaiEnvConfigExcep
78
86
79
87
// 初始化一些参数
80
88
this .initTaintToStringCharLimit ();
81
-
89
+ this . initPool ();
82
90
}
83
91
84
92
public static String getTmpDir () {
@@ -244,6 +252,34 @@ public static Integer getTaintToStringCharLimit() {
244
252
return instance .taintToStringCharLimit ;
245
253
}
246
254
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
+
247
283
/**
248
284
* 初始化taintToStringCharLimit参数的值
249
285
*
@@ -274,6 +310,36 @@ public void initTaintToStringCharLimit() throws DongTaiPropertyConfigException,
274
310
275
311
}
276
312
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
+
277
343
/**
278
344
* Property文件配置错误
279
345
*/
0 commit comments