简体   繁体   中英

Mule Java Component and Thread Safe

An excerpt from this http://www.mulesoft.org/documentation/display/current/Configuring+Java+Components is:

When you specify the class directly on the component or pooled-component element, the PrototypeObjectFactory is used by default, and a new instance is created for each invocation, or a new pooled component is created in the case of the PooledJavaComponent

And, I have configured a Java class as Mule Java component like below:

<component class="com.mycompany.SalesOrderProductsHandler" doc:name="Java" /> . The class SalesOrderProductsHandler has implemented org.mule.api.lifecycle.Callable and has one state variable named targetProductsIndex .

My question follows:

Will a new instance of com.mycompany.SalesOrderProductsHandler get created every time a new request comes?

The documentation is absolutely correct. With:

<component class="com.mycompany.SalesOrderProductsHandler" />

you will get a new instance of com.mycompany.SalesOrderProductsHandler for each invocation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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