Posted: Thu Oct 10, 2002 2:47 pm Post subject: Is the Environment structure thread safe?
Apprentice
Joined: 25 Sep 2002 Posts: 28
I have deployed a message flow and specified 100 additional intances.
I need a global variable that is thread safe that I can store a simple counter in. So that each message that comes through the flow
increments this counter by one. I tried storing this counter in a DB2
DB, but the read operation is not blocking so multiple thread read the counter at the same time...not good. I also don't want to make the whole flow transactional, because that would defeat the purpose of bumping up the additional instance count on the message flow. I tried the following:
IF Environment.newtrxnId IS NULL then
SET Environment.newtrxnId = 1;
else
SET Environment.newtrxnId = CAST(Environment.newtrxnId AS INTEGER) + 1;
end IF;
But I found that Environment must not be thread safe because all my newtrxnId were equal to 1. Any Ideas?
A new Environment is created for every message read from an MQInput node. It is not a cross thread storage area. It is thread safe, because only one thread can see it! To store information between threads and between messages you ought to use a database. If you make the flow transactional, then your database read will be blocking. This is probably ok performance wise if you can leave the operation as late as possible in your flow.
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