B4J Question Handler gets Class Instance from Worker. In which thread do the Class Instance's methods run?

hatzisn

Expert
Licensed User
Longtime User
I used codex to find the answer in this question. I have got the following. Are they correct?

 

hatzisn

Expert
Licensed User
Longtime User
I haven't read all of it, sorry.

The answer is:
Unless you called the target class instance with CallSubDelayed, then it will run on the same thread. With CallSubDelayed, it will run on the target class instance owner thread.

Thank you for the reply. What is mentioned as an answer about concurrency in question 2 (as seen above), is it correct?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, the way to test the behavior is by checking the value of Main.srvr.CurrentThreadIndex. And it must be in release mode or it will always be 0.

It is correct. The code will run concurrently even if it is the same class instance. This means that if you are relying on class global variables then you can have race conditions.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…