Thread safety in Java Collaborations

Is it necessary to write Java Collaborations in a thread safe manner? If so, under what scenario can a JCD become multithreaded?
[135 byte] By [AKsuited] at [2008-2-2]
# 1

It is not necessary to write code in JCD in thread safe manner, unless you want some piece of code which should be thread safe.

Number of threads are configurable in the integration server properties and JCD will be multithreaded automatically if more than 1 request come to the server simultaneously.

achintaysagar at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 2

Of course, I want the JCD to be thread safe, if indeed there would be multiple threads executing in the JCD instance. That is the essence of my question.

If I understand your response, the JCD instance could be multithreading if it is processing more than one request. Then, my question is - under which scenarios would a JCD instance be certain to process only one request - single threaded, and which scenarios would the JCD instance possibly process multiple requests - multithreaded.

For example, if my JCD implements an existing web service - a JMS receive - is it possible for it to be processing more than one request at a time? What if the connectivity map had more than one instance of the same JCD consuming messages from a common queue either in serial mode or connection consumer mode? Or, what if the JCD was invoked by a Business Process?

Thanks for your reply.

Message was edited by:

AKsuited

AKsuited at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 3

A JCD is like a MDB. If you access information that is thread safe, thent he JCD is inherently thread safe.

The body of a JCD is java. So you could access static classes, and not protect them, which would make your jcd non thread safe. Same if you would start creating your own threads.

The short answer is yes they are thread safe. And when there is more than one being executed at the same time, the behavior is about the same as an MDB.

But depending on your coding style, you can do code that is not thread safe.

For the JMS examples, you are safe, as the data is never the same ( a new message each time).

for the eInsight process that is a scenario to test. Not necessarily because the jdc would not be "multithreaded" but think of the following situation.

You have a process that need to work on a xml message. Then you set up a path one to N path split, each of the n path doing a simple processing on the xml message, which theorically you could process in parallel. Now, each jcd call takes the xml message and updates a status field in the xml message. Now what would be the outcome? Would it be predictable? How would the data concurrency be handled in eInsight? Are the jdc being handed copies of the xml message or a pointer to it?

Worth some testing don't you think?

;o)

TE

TravelEntity at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 4

The implementation is a bit more complex then this. When you create a JCD that implements an existing web service (ie a JCD that is started by a connector), eDesigner will create a message driven bean that is triggered by the connector and a stateless session bean that will be called from the message driven bean. This stateless session bean will call your JCD web service method, the receive or the start method.

Because your JCD is hosted in a stateless session bean it will receive all the benefits of the J2EE thread and instance management. If there are multiple JMS messages to process, the application server can create multiple instances of the stateless session bean that hosts your JCd and thereby multiple instances of your JCD class will be created. If these are no longer needed, the application server can destroy them. As stateless session beans are thread safe, you do not need to code your JCD's in a thread safe manner. Of course if you want to access static resources or use singletons then you will need to access these in a threda safe manner from the JCD.

When you JCD's are started by a JMS message (this is when your JCD's implement the JMS receive web service), you can configure in the connectivity map how many instances of your JCD can be started concurrently by the application server. When double clicking the configuration block on the JMS inbound connection you can specify two options:

- Connection Consumer or Serial mode: multiple instances can be started when multiple messages are available or not.

- Server session pool size: how many instances can be created.

Frederik@NL at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 5

Frederik,

Thank you for your reply - it helps a lot. I do have one more question - as you begin your reply with "When you create a JCD that implements an existing web service ..." etc. How is the JCD different when it implements a new web service? Is it not hosted by a stateless session bean that is called from a message driven bean?

Thanks again.

Message was edited by:

AKsuited

AKsuited at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 6

If your message is implementing a new web service instead of an existing web service, it will still be hosted by a stateless session bean. However, because it will not be triggered by a connector, no message driven bean will be generated.

If you Java collaboration is exposed as an external callable web service, the stateless session bean will be called by the servlet, if your collaboration is called from en eInsight business process, the stateless session bean will be called by a message driven bean that is triggered from the eInsight BPEL engine. The eInsight BPEL engine is implemented as a JCA connector and a single message driven bean exists to allow it to call Java collaborations. This message driven bean is not generated when you define a new java collaboration but is predefined and linked to the eInsight engine.

Regards,

Frederik

Frederik@NL at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 7

Hello,

Is there a way to allow concurrency when we define a jcd exposed as a new web service? I.e. When we call the new web service several times at the same moment, the calls are processed parallelly and not sequentially.

What are the different options to achieve this ?

Is it manadatory to go through eInsight or can we reach the result with eGate only ?

Thanks for your help !

Nicolas

Degroof at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 8

Hello,

It seems it is not possible ? It is a pity because when building a composite application taking data from backend systems via web services (this is the famous SOA buzz...) you would expect a possibility to call the web services in parallel to ensure scalability....

The only options I have seen so far are:

- using a BP

- using the http inbound eway (not a "true" web service then)

Any other idea's ?

Thanks

Nicolas

Degroof at 2007-7-7 > top of java,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...