简体   繁体   English

Camunda BPM的JavaDelegate类是否应该是线程安全的?

[英]Should JavaDelegate classes for Camunda BPM be thread safe?

The main question is about static fields and singleton instances (for configs, etc.) - are instances of one process running in different threads, as usual servlet requests? 主要问题是关于静态字段和单例实例(对于配置等) - 是一个进程在不同线程运行的实例,就像通常的servlet请求一样?

If look deeper - do different @ProcessApplication run in one JVM and will see the same singletons? 如果看得更深 - 在一个JVM中运行不同的 @ProcessApplication并看到相同的单例吗? I don't think so. 我不这么认为。 I know exactly that their classes don't see each other and can have equal names (because of different classLoaders?) 我确切地知道他们的类没有看到对方并且可以有相同的名称(因为不同的classLoaders?)

Haven't found any meaningful info on these important themes about Camunda, will appreciate your answers. 没有找到关于Camunda这些重要主题的任何有意义的信息,将非常感谢您的回答。

I had this same question for one of our scenario while back, and read their Javadoc as mentioned here for a servlet container. 回到过程中,我对我们的一个场景有同样的问题,并阅读这里提到的用于servlet容器的Javadoc Extracting Javadoc, 提取Javadoc,

Invocation Semantics 调用语义

When the {@link #execute(java.util.concurrent.Callable)} method is invoked, the servlet process application modifies the context classloader of the current Thread to the classloader that loaded the application-provided subclass of this class. 当调用{@link #execute(java.util.concurrent.Callable)}方法时,servlet进程应用程序将当前Thread的上下文类加载器修改为加载此类的应用程序提供的子类的类加载器。 This allows, 这允许,

  • the process engine to resolve {@link JavaDelegate} implementations using the classloader of the process application 使用流程应用程序的类加载器解析{@link JavaDelegate}实现的流程引擎

This pretty much explain everything you want to know, since the behavior is very similar to how a web container operates. 这几乎可以解释您想要了解的所有内容,因为该行为与Web容器的运行方式非常相似。 If you want to know how other container implementations behaves, you can check the respective Javadocs of classes in this package . 如果您想知道其他容器实现的行为,可以检查此包中各自的Javadoc


To answer your question: 回答你的问题:

Yes . 是的 Thread-safety is required for the shared-resources accessed by JavaDelegate in the same process application. JavaDelegate在同一个流程应用程序中访问的共享资源需要线程安全性。 According to the documentation (see below) they create a new instance of delegate each time a task is going to be executed. 根据文档 (见下文) 每次执行任务时, 他们都会创建一个新的委托实例

Note! 注意!

Each time a delegation class referencing activity is executed, a separate instance of this class will be created. 每次执行委托类引用活动时,都将创建此类的单独实例。 This means that each time an activity is executed there will be used another instance of the class to call execute(DelegateExecution). 这意味着每次执行一个活动时,都会使用该类的另一个实例来调用execute(DelegateExecution)。

Therefore, at any time there can be many delegate instances actively running due to the multiple invocation of Process Definitions . 因此,由于多次调用Process Definitions ,在任何时候都可能有许多委托实例正在运行。 So, if they are accessing a shared resource, then they need to be synchronized (thread-safe), because, that shared resources ( static or singleton ) is local to the process application and loaded by respective application classloader according to above Invocation Semantics Javadoc. 因此,如果他们正在访问共享资源,那么他们需要进行同步(线程安全),因为共享资源( 静态单例 )是流程应用程序的本地资源,并由相应的应用程序类加载器根据上面的调用语义 Javadoc加载。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM