some questions about ThreadSafeMap in a jServer environment:
a Map that is loaded once with CreateMap(...) at startup and is used only with Get, does not need to be a ThreadSafeMap, correct?
a Map created in a ServerHandler Class_Globals, and used only within that class, does not need to be a ThreadSafeMap, correct?
a Map in a Process_Globals, accessed with Get and Put should be a ThreadSafeMap, correct?
a Map that should be a ThreadSafeMap, but is erroneously declared as Map, can cause an exception at runtime or just unpredictable results because of eventual concurrent write access?
I'm fairly positive about 1, 2, and 3, but in doubt about 4, and would like some feedback from users more experienced with the server environment.
and last but not least, what is the correct way to obtain a Lock on a ThreadSafeMap for a read/modify/write operation?
I'm not a great expert, but I agree with you on the first three points.
For point 4, which is related to the last part of your question, I'd say you should prevent direct access to that Map, meaning you should create a Subroutine to manage it (which is the same difference between creating a public variable instead of creating the Subroutines setSomething and / or getSomething to protect the variable, not allowing invalid values to be assigned to it).
In B4J, a Java-based development environment, there is no specific class called ThreadSafeMap like in standard Java, but synchronization of access to a Map can be managed to make it thread-safe using manual synchronization techniques typical of B4J or Java.
A common option is to use a regular Map object and synchronize its access with critical blocks using the synchronized keyword or locks (for example, using the JavaObject class to access Java synchronization if necessary). Another simpler approach in B4J is to use your Map object within a Synchronized object using the Sync statement to protect sections of code that access or modify the Map, preventing uncontrolled concurrent access.
In B4J, a Java-based development environment, there is no specific class called ThreadSafeMap like in standard Java, but synchronization of access to a Map can be managed to make it thread-safe using manual synchronization techniques typical of B4J or Java.
A common option is to use a regular Map object and synchronize its access with critical blocks using the synchronized keyword or locks (for example, using the JavaObject class to access Java synchronization if necessary). Another simpler approach in B4J is to use your Map object within a Synchronized object using the Sync statement to protect sections of code that access or modify the Map, preventing uncontrolled concurrent access.
In Java, ConcurrentHashMap is a class that provides a thread-safe implementation of a map, similar to the idea of ThreadSafeMap. ConcurrentHashMap allows multiple threads to access and modify the map simultaneously, without requiring the entire data structure to be locked, as a conventional Hashtable would.