在多线程应用程序中,我使用了很棒的 Apache Commons 库。但是,由于某种原因,我的一半线程在调用其getList和类似方法时被阻塞。
这是线程转储的示例:
java.lang.Thread.State: BLOCKED (on object monitor)
at org.apache.commons.configuration.interpol.ConfigurationInterpolator. (ConfigurationInterpolator.java:138)
- locked <0x00000000855e6138> (a java.util.HashMap)
at org.apache.commons.configuration.AbstractConfiguration.createInterpolator(AbstractConfiguration.java:328)
at org.apache.commons.configuration.AbstractConfiguration.getSubstitutor(AbstractConfiguration.java:292)
- locked <0x00000000d7293058> (a org.apache.commons.configuration.SubsetConfiguration)
at org.apache.commons.configuration.PropertyConverter.interpolate(PropertyConverter.java:958)
at org.apache.commons.configuration.AbstractConfiguration.interpolate(AbstractConfiguration.java:446)
at org.apache.commons.configuration.SubsetConfiguration.interpolate(SubsetConfiguration.java:213)
at org.apache.commons.configuration.SubsetConfiguration.interpolate(SubsetConfiguration.java:218)
at org.apache.commons.configuration.AbstractConfiguration.interpolate(AbstractConfiguration.java:433)
at org.apache.commons.configuration.SubsetConfiguration.interpolate(SubsetConfiguration.java:224)
at org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1039)
at org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1018)
每次线程被阻塞(通过getList或getInt或类似方法)时,锁都在 ConfigurationInterprator 类中。通过查看它的源代码,我了解到类的实例化是同步的——但是我只需要能够读取属性,并且不需要每次都进行插值。
Apache Commons 中是否有内置方法来克服此限制?例如,不要每次都采取插值步骤并以某种方式缓存它?
谢谢,克里斯