[jboss-jira] [JBoss JIRA] (DROOLS-787) getProcessRuntimeFactoryService method of ProcessRuntimeFactory is synchronized.
René Zanner (JIRA)
issues at jboss.org
Wed Aug 19 05:30:27 EDT 2015
[ https://issues.jboss.org/browse/DROOLS-787?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13099727#comment-13099727 ]
René Zanner commented on DROOLS-787:
------------------------------------
We have the same issue here - it dramatically reduces scalability. Even when there is no ProcessRuntimeFactoryService available, every thread is blocked by this call during creation of a StatefulKnowledgeSessionImpl...
I would suggest to statically initialize this singleton in ProcessRuntimeFactory - without any synchronization, since the static initialization of a class is synchronized automatically by the VM.
{code}
private static ProcessRuntimeFactoryService provider = initializeProvider();
private static ProcessRuntimeFactoryService initializeProvider() {
ServiceRegistryImpl.getInstance().addDefault(ProcessRuntimeFactoryService.class,
"org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl");
ProcessRuntimeFactoryService service = null;
try {
service = ServiceRegistryImpl.getInstance().get(ProcessRuntimeFactoryService.class);
} catch (IllegalArgumentException e) {
LOGGER.warn(e.getMessage(), e);
}
return service;
}
public static InternalProcessRuntime newProcessRuntime(StatefulKnowledgeSessionImpl workingMemory) {
if (provider == null) {
LOGGER.warn("Could not load the ProcessRuntimeFactoryService from ServiceRegistryImpl - returning 'null'.");
return null;
}
return provider.newProcessRuntime(workingMemory);
}
{code}
The only thing that's missing then is the possibility to reset and dynamically re-initialize this singleton.
When that *really* is a requirement, then there should be implemented some state-of-the-art synchronization, i.e. Double-checked locking (as of Java 5 with the {{volatile}} keyword it's even working, see https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java or http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html).
Nowadays there's really no need to synchronize the whole getter.
> getProcessRuntimeFactoryService method of ProcessRuntimeFactory is synchronized.
> --------------------------------------------------------------------------------
>
> Key: DROOLS-787
> URL: https://issues.jboss.org/browse/DROOLS-787
> Project: Drools
> Issue Type: Bug
> Environment: software platform
> Reporter: vipul gajara
> Assignee: Petr Široký
>
> getProcessRuntimeFactoryService is getter method of singleton class "org.drools.core.runtime.process.ProcessRuntimeFactory" but this method is static synchronized so at a time only one thread can call it .
> Due to above issue when we are using drools in multi threaded enviorenment threads are getting locked at this method and performance degrades when creating KSession objects.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
More information about the jboss-jira
mailing list