Author |
Message
|
gauraveca |
Posted: Mon Mar 30, 2015 7:22 pm Post subject: Is Java Compute Node Singleton ? |
|
|
 Newbie
Joined: 15 Jan 2015 Posts: 5
|
Hi
I am new to broker. We have a use case where we need to use java compute node for some transformation.
I need to know whether the class for my java compute node is a singleton ? For every incoming request a new instance of the class is created ?
I tried searching but couldn't find an answer to this.
Thanks |
|
Back to top |
|
 |
Vitor |
Posted: Tue Mar 31, 2015 4:29 am Post subject: Re: Is Java Compute Node Singleton ? |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
gauraveca wrote: |
I tried searching but couldn't find an answer to this.
|
I'm suprised the searching didn't turn up the InfoCenter piece on the Java Compute Node.
gauraveca wrote: |
I need to know whether the class for my java compute node is a singleton ? For every incoming request a new instance of the class is created ? |
Why? I'm by no means the Java guy, but isn't the point of a singleton that there's only one of it between multiple instances? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Mar 31, 2015 4:41 am Post subject: Re: Is Java Compute Node Singleton ? |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
gauraveca wrote: |
I tried searching but couldn't find an answer to this.
|
I'm suprised the searching didn't turn up the InfoCenter piece on the Java Compute Node. |
Quote: |
Only one instance of the JavaCompute node is created regardless of the number of threads that are running against the flow (either as a result of extra instances or multiple input nodes). |
The most important skill you can have when working wtih any technology is understanding how to use the documentation it provides.
The second most important skill is how to convince the maintainers to ensure the documentation is useful... |
|
Back to top |
|
 |
mapa |
Posted: Tue Mar 31, 2015 5:24 am Post subject: Re: Is Java Compute Node Singleton ? |
|
|
 Master
Joined: 09 Aug 2001 Posts: 257 Location: Malmö, Sweden
|
Vitor wrote: |
I'm suprised the searching didn't turn up the InfoCenter piece on the Java Compute Node.
|
Why read about how the JCN works when you can post a question here?
The link Vitor provided clearly express how it works if you read it.
However it does not mention Singleton (which is a design pattern) but if you know how the Singleton pattern works in Java you will know if the JCN is one or not if you read about it. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Mar 31, 2015 5:28 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
@mqjeff:
Arguably, this
Quote: |
Only one instance of the JavaCompute node is created |
...could be interpreted in terms of the node, and not the Java class that implements the user's transformation logic.
You and I know that it's talking about the latter, but it's not necessarily obvious.
@gauraveca:
There is sometimes a need to have a singleton class ( a common reason is to implement a process-wide cache for all message flows. Can be useful for storing session state, reference data etc. ). As mapa points out, you can easily implement one ( but make sure that you do some research on Java best practices first - it is easy to get it wrong ). _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Mar 31, 2015 5:31 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
...and before somebody else points it out, you may want to investigate using the global cache ( genuinely global ) before implementing a cache that can only be accessed from one OS process/execution group/integration server. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
gauraveca |
Posted: Tue Mar 31, 2015 9:24 pm Post subject: |
|
|
 Newbie
Joined: 15 Jan 2015 Posts: 5
|
Thank you all for your replies. Apologies i didn't checked out the documentation in details. I did checked out the documentation and have some confusion or it might be my lack of experience in broker and java as i am just starting out.
This page says
http://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac20805_.htm
"Only one instance of the JavaCompute node is created regardless of the number of threads that are running against the flow (either as a result of extra instances or multiple input nodes). Therefore, all of your user Java code must be threadsafe and reentrant."
And this one says
http://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac01541_.htm?lang=en
In the message flow execution environment, the message flow is thread-safe. You can run message flows concurrently on many operating system threads, without having to consider serialization issues. Each input message that passes through a message flow for processing by a series of nodes executes on a single thread; it is processed only by the thread that received it.
The confusion is in the first article it asks the user to write the java code which is thread safe, however in the second article it says that the message flow itself is thread safe. So if the message flow is thread safe why do i need to explicitly write thread safe java code ? |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 01, 2015 4:32 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
gauraveca wrote: |
So if the message flow is thread safe why do i need to explicitly write thread safe java code ? |
Because only one instance of your JavaComputeNode class is created, and so all message flow threads will call it. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 01, 2015 4:55 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
gauraveca wrote: |
The confusion is in the first article it asks the user to write the java code which is thread safe, however in the second article it says that the message flow itself is thread safe. So if the message flow is thread safe why do i need to explicitly write thread safe java code ? |
The message flow is thread safe in that a message, once consumed by a given thread instance of the flow, will only be processed by that thread and flow artifacts (such as the Environment tree) are not shared / cross contaminated / locked by other thread instances of the same flow. The ESQL and the rest of the inbuilt functionality provide this thread safety by design.
To preserve this flow level thread safety it's essential that user written Java code is equally thread safe, as Java is the only part of the flow where it's physically possible to break the thread safe model; you simply can't write thread crossing ESQL, the language doesn't support or allow it.
You'll find the same requirement for thread safe code in the InfoCenter pieces about user defined nodes and user defined parsers, for the same reason. But you'll write Java Compute Nodes much, much more frequently. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Apr 01, 2015 5:25 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
you simply can't write thread crossing ESQL, the language doesn't support or allow it |
You can, if you declare SHARED variables in your ESQL.
Vitor knows this, of course. He just chose not to say it. And I only chose to say in order to annoy Vitor  _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 01, 2015 5:34 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
kimbert wrote: |
Quote: |
you simply can't write thread crossing ESQL, the language doesn't support or allow it |
You can, if you declare SHARED variables in your ESQL. |
Only the data crosses the threads, not the code... |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 01, 2015 6:04 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
kimbert wrote: |
Quote: |
you simply can't write thread crossing ESQL, the language doesn't support or allow it |
You can, if you declare SHARED variables in your ESQL.
Vitor knows this, of course. He just chose not to say it. And I only chose to say in order to annoy Vitor  |
This I assume to be the 2nd part of your cunning plan, the 1st part being to have one of your minions sabotage the coffee machine.....
....I echo the comments of yourself and our most worthy associate. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
gauraveca |
Posted: Thu Apr 02, 2015 10:27 pm Post subject: |
|
|
 Newbie
Joined: 15 Jan 2015 Posts: 5
|
Thank you all for the help. I understand it now.
kudos to the community here. |
|
Back to top |
|
 |
|