B4J Question [solved]webapp Raf write/read object and threadsafe maps

billzhan

Active Member
Licensed User
Hi,

I have more questions on webapp (threadsafe) maps and raf.WriteObject.

1. I have some normal maps initialized with keys/values added. These maps will only be read from other concurrent threads(no modification/del). Are they thread safe?
Info:
http://stackoverflow.com/questions/...va-util-hashmap-from-multiple-threads-no-modi


2. Is it OK to save thread safe maps with Raf.writeobject/readobject? Or I have to write/read by normal maps?


Tks,
bz
 
Last edited:

Erel

Administrator
Staff member
Licensed User
1. Yes. As long as no thread modifies the map then it can be shared. Note that ConcurrentHashMaps (thread safe maps) are very fast and their performance is close to regular maps. So in most cases you can just use the thread safe maps.

2. Yes. You can. However when you read the object a regular map will be created.
Consider using a real database for a server app. You can use SQLite databases if you want to have a "zeo configuration" solution: [WebApp] Concurrent access to SQLite databases
 
Upvote 0

billzhan

Active Member
Licensed User
Thanks.

Previous work will be modified to thread safe map.

I actually use SQLite db in wal mode a lot. Maps are used to store values need most frequent access.
Raf writeobj/readobject are used to share data with clients.
 
Upvote 0
Top