ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » shared Variables confusion

Post new topic  Reply to topic Goto page 1, 2  Next
 shared Variables confusion « View previous topic :: View next topic » 
Author Message
sush1988_07
PostPosted: Fri Oct 05, 2012 11:25 am    Post subject: shared Variables confusion Reply with quote

Newbie

Joined: 03 Oct 2012
Posts: 5

Hi!! I have read quite a few times what shared variable is. But I'm not being able to relate to it with an example. Can anybody explain it to me using a small example? I just need to see a use of it to understand it. Thank you
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Oct 05, 2012 11:28 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Suppose you need to keep a count of messages processed over a given day.

You could use a shared variable to store the count, use an atomic block to ensure that it's incremented correctly across threads, and then another shared variable to store what day it is and find out if you need to reset the count when it's a new day or not.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Fri Oct 05, 2012 11:30 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

Shared variables have a long lifetime and are visible to multiple messages. They are useful for storing a message counter, for example. You cannot share variables across execution groups. It is not wise to overuse shared variables.

If you have alot of data you want to cache between messages, use a database, a Singleton, or an in-memory solution like solidDb.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Fri Oct 05, 2012 11:32 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

lancelotlinc wrote:
If you have alot of data you want to cache between messages, use a database, a Singleton, or an in-memory solution like solidDb.


Or the global cache that comes with 8.0.0.1 and later...
Back to top
View user's profile Send private message
sush1988_07
PostPosted: Fri Oct 05, 2012 11:49 am    Post subject: Reply with quote

Newbie

Joined: 03 Oct 2012
Posts: 5

Thanks guys. I understand when u say it can be used to store a count but then initialized to begin a new one. But when it says it is visible to multiple messages then what use is made out of it?
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Oct 05, 2012 11:53 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

sush1988_07 wrote:
Thanks guys. I understand when u say it can be used to store a count but then initialized to begin a new one. But when it says it is visible to multiple messages then what use is made out of it?


Each message received by an input node is processed in an independent thread.

A shared variable persists across threads. No other ESQL variables are visible in any other thread than the one processing the current message.

So if you just use a regular variable in a Compute node, and increment it each time you process a message, then the count will only ever by '1'.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Fri Oct 05, 2012 11:54 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

sush1988_07 wrote:
it can be used to store a count


SET I = I + 1;

sush1988_07 wrote:
initialized to begin a new one.


SET I = 1;

sush1988_07 wrote:
what use is made out of it?


SET OutputRoot.MQMD.ApplIdentityData = I;
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
sush1988_07
PostPosted: Fri Oct 05, 2012 1:00 pm    Post subject: Reply with quote

Newbie

Joined: 03 Oct 2012
Posts: 5

ok Thanks mqjeff and lancelotlinc. one last question, how can i see a problem and say this needs a shared variable?
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Oct 05, 2012 1:21 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

sush1988_07 wrote:
how can i see a problem and say this needs a shared variable?


Why a problem? You're more likely to see a design requirement similar to the scenarios described above.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
sush1988_07
PostPosted: Fri Oct 05, 2012 1:27 pm    Post subject: Reply with quote

Newbie

Joined: 03 Oct 2012
Posts: 5

hi. so the use is just for counts?
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Oct 05, 2012 1:35 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

The use is for any kind of data that you need to manage across instances of a single message flow.

You will identify a problem where you can use a shared variable through the combination of your intelligence and your experience.
Back to top
View user's profile Send private message
sush1988_07
PostPosted: Fri Oct 05, 2012 1:40 pm    Post subject: Reply with quote

Newbie

Joined: 03 Oct 2012
Posts: 5

thanks guys!!
Back to top
View user's profile Send private message
manan.patel
PostPosted: Mon Oct 08, 2012 12:39 am    Post subject: Reply with quote

Apprentice

Joined: 01 Oct 2012
Posts: 25

can anybody please post an example....
Back to top
View user's profile Send private message
mqsiuser
PostPosted: Mon Oct 08, 2012 12:51 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

manan.patel wrote:
can anybody please post an example....


You can use a variable, which is declared as a SHARED ROW in the same way as the InputRoot or OutputRoot.
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Wed Oct 10, 2012 5:33 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

manan.patel wrote:
can anybody please post an example....


No. do your own research and homework. Attend the requisite training.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » shared Variables confusion
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.