Maybe using an asynchroneous message helps in your case? ( An example ( Communicating between Object REXX threads

Maybe using an asynchroneous message helps in your case? ( An example ( Communicating between Object REXX threads

Post by rony » Sun, 01 Aug 2004 09:23:45


Bob:

how about the following (which would make your problem rather simple to solve):

- define a class ("BobSQL") with one method "dispatchSQL" or whatever
- create a single instance of it and store it in .local or .environment (e.g. ".local~sql.interface=.bobSQL~new")
- in whatever part of your code just invoke the method "dispatchSQL" *asynchroneously* using the environment symbol
.sql.interface, e.g.

... have somewhere define your SQL-statement and place it in a variable, e.g. "mySQLstmt":
msgObj=.message~new(.sql.interface, "dispatchSQL", "I", mySQLstmt)~start

... now do whatever you want, whenever you want to know whether your message got processed do something like:

if msgObj~completed then -- if the message was processed this returns .true, .false else
res=msgObj~result -- get the result that the processed message returned, if any
... now do whatever you want...
end
...

Now, if you have multiple SQL invocations from different threads/places, they should get serialized by the runtime
(there is just one object and its method "dispatchSQL" is guarded/serialized with other methods from the same class)
*and* you are able to retrieve the result asynchronesously, hence all these different threads may execute concurrently.

Is that (having concurrent execution) not necessary then use the method "send" above which synchroneously executes the
message and waits for it to finish; if it returns a value than assign it to a variable (e.g.
"res=.message~new(.sql.interface, 'dispatchSQL', 'I', mySQLstmt)~send"). (Cf. online documentation for class .Message).

Hope that helps,

---rony