我们最近将Drools引入我们的系统,很快一段时间后我们的服务器开始行为不端(崩溃或延迟增加),我们分析了线程转储和来自下面的代码片段。此池中的大多数线程都处于BLOCKED STATE状态。
"mainProcessPool-pool-18-thread-1078--ADDADA121312" - Thread t@21148
java.lang.Thread.State: BLOCKED
at org.apache.catalina.loader.WebappClassLoader.findResources(WebappClassLoader.java:1312)
- waiting to lock <97872c0> (a [Ljava.util.jar.JarFile;) owned by "mainProcessPool-pool-18-thread-1019--ADDADA121312" t@20949
at java.lang.ClassLoader.getResources(ClassLoader.java:1040)
at org.drools.util.CompositeClassLoader.getResources(CompositeClassLoader.java:116)
at org.drools.util.ChainedProperties.getResources(ChainedProperties.java:146)
at org.drools.util.ChainedProperties.<init>(ChainedProperties.java:92)
at org.drools.util.ChainedProperties.<init>(ChainedProperties.java:51)
at org.drools.SessionConfiguration.init(SessionConfiguration.java:140)
at org.drools.SessionConfiguration.<init>(SessionConfiguration.java:124)
at org.drools.impl.KnowledgeBaseImpl.newStatefulKnowledgeSession(KnowledgeBaseImpl.java:155)
at com.tnp.drools.configuration.DroolsConfigManager.getStatefullSession(DroolsConfigManager.java:103)
只是想知道什么可以是相同的详细原因。我应该采取哪些其他配置来防止此类问题。
====使用JAVA CONFIG更新
public class DroolsConfigManager {
private KnowledgeAgentConfiguration knowledgeAgentConfig;
private Properties config;
private String droolCachePath;
private ResourceChangeScannerConfiguration rChangeScannerConfiguration;
private KnowledgeAgent knowledgeAgent;
public String getDroolCachePath() {
return this.droolCachePath;
}
public void setDroolCachePath(String droolCachePath) {
this.droolCachePath = droolCachePath;
}
public KnowledgeAgent getKnowledgeAgent() {
return this.knowledgeAgent;
}
public void setKnowledgeAgent(KnowledgeAgent knowledgeAgent) {
this.knowledgeAgent = knowledgeAgent;
}
public ResourceChangeScannerConfiguration getrChangeScannerConfiguration() {
return this.rChangeScannerConfiguration;
}
public void setrChangeScannerConfiguration(ResourceChangeScannerConfiguration rChangeScannerConfiguration) {
this.rChangeScannerConfiguration = rChangeScannerConfiguration;
}
public Properties getConfig() {
return this.config;
}
public void setConfig(Properties config) {
this.config = config;
for (Object key : config.keySet()) {
if (this.knowledgeAgentConfig == null)
this.knowledgeAgentConfig = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
this.knowledgeAgentConfig.setProperty((String) key, (String) config.get(key));
}
}
public KnowledgeAgentConfiguration getKnowledgeAgentConfig() {
return this.knowledgeAgentConfig;
}
public void setKnowledgeAgentConfig(KnowledgeAgentConfiguration knowledgeAgentConfig) {
this.knowledgeAgentConfig = knowledgeAgentConfig;
}
public void start() {
if(this.droolCachePath != null){
System.setProperty("drools.resource.urlcache", this.droolCachePath);
}
this.rChangeScannerConfiguration = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
this.rChangeScannerConfiguration.setProperty(ApplicationConstants.DROOLS_RESOURCE_SCANNER_INTERVAL, this.config.getProperty(ApplicationConstants.DROOLS_RESOURCE_SCANNER_INTERVAL));
ResourceFactory.getResourceChangeScannerService().configure(this.rChangeScannerConfiguration);
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
this.knowledgeAgent = KnowledgeAgentFactory.newKnowledgeAgent(this.config.getProperty(ApplicationConstants.DROOLS_KNOWLEDGE_AGENT_NAME), this.knowledgeAgentConfig);
Resource resource = ResourceFactory.newClassPathResource(this.config.getProperty(ApplicationConstants.DROOLS_BASE_KNOWLEDGE_AGENT_CHANGE_SET_PATH));
this.knowledgeAgent.applyChangeSet(resource);
}
public StatelessKnowledgeSession getStatelessSession() {
KnowledgeAgent knowledgeAgent = getKnowledgeAgent();
return knowledgeAgent.getKnowledgeBase().newStatelessKnowledgeSession();
}
public StatefulKnowledgeSession getStatefullSession() {
KnowledgeAgent knowledgeAgent = getKnowledgeAgent();
return knowledgeAgent.getKnowledgeBase().newStatefulKnowledgeSession( );
}
}
我们正在使用StatefulKnowledgeSession,public StatefulKnowledgeSession getStatefullSession()
方法。我们创建了这个类的Spring bean,并在其他类中注入以使用drools。