Why do we need to declare a constant as Shared Constant?

890 Views Asked by At

In ESQL we have SHARED CONSTANTS, Why do we need them when they are constant and they don't change even if multiple threads access the same value.

DECLARE MYCONST SHARED CONSTANT CHAR 'My Constant';

OR in general I would like to know why do we need shared constants??

2

There are 2 best solutions below

0
On

Using my immagination, you can declare a constant shared to not duplicate a BIG variable among Flows.
For Example, it could be useful in a multiple instances flow if you want to send a every-time-the-same message and you want to save time. It could be already in memory with:

   DECLARE MYVAR SHARED CONSTANT BLOB X'0000' ;

I think that this need is very much infrequent.
And even more infrequent to take advantage from this: if the blob is too big simply is counterproductive to put in a global variable.

0
On

According to this post, it takes more time to read a SHARED CONSTANT than a normal CONSTANT. There seems to be a locking mechanism for all shared variables, including constants.

But probably all non shared CONSTANTs are copied to the memory at the start of each flow instance. I would say, if you have a lot of constants and each flow only accesses a few of them, SHARED CONSTANTS are more performant.

If performance is an issue, I would test which option processes the data in less time. But there is no solution that is best for every single messageflow.