I just can't seem to understand how threading works in B4J.
A server class instance runs in its own thread ... When I call a method of a global class instance (like the chat shared in the example) inside a server class instance: does this run on the main thread on within the thread of the server class instance ?
A server also allows to create a threadsafe map (CreateThreadSafeMap)... But what happens in this example (in consecutive order)
1. Server class instance A checks whether key X exists
2. Server class instance B checks whether key X exists
3. Server class instance A sees the key does dot exist and it adds a key
4. Server class instance B also came to the conclusions the key did not exist (step 2) and wants to add it as well
--> error because meanwhile the key was already created.
So I understand the Map could work threadsafe internally but I would assume I still need something like a critical section/semaphore to protect code in a class (where step 1 & 3 on one side and 2 & 4 on the other would be protected) ?
Thanks
A server class instance runs in its own thread ... When I call a method of a global class instance (like the chat shared in the example) inside a server class instance: does this run on the main thread on within the thread of the server class instance ?
A server also allows to create a threadsafe map (CreateThreadSafeMap)... But what happens in this example (in consecutive order)
1. Server class instance A checks whether key X exists
2. Server class instance B checks whether key X exists
3. Server class instance A sees the key does dot exist and it adds a key
4. Server class instance B also came to the conclusions the key did not exist (step 2) and wants to add it as well
--> error because meanwhile the key was already created.
So I understand the Map could work threadsafe internally but I would assume I still need something like a critical section/semaphore to protect code in a class (where step 1 & 3 on one side and 2 & 4 on the other would be protected) ?
Thanks
Last edited: