• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to share a hashtable for read only purpose between several threads ?

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
thank you for reading my post
how i should share a hashtable between several threads ?
threads are intended to just read the stuff from the hashtable (indeed thread will use its contains and containsKey method of hashtable)
should i add that hashtable with all its initial elements to thread class ?
(my threads are from a class that implements the runnable interface)
or it is better that i add that hashtable to another class and use it inside threads ?
but i should create an instance of that class in all threads to use the hashtable property of that class....

Thanks.
 
Henry Wong
author
Sheriff
Posts: 22541
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly sure what you are asking -- but a Hashtable object should be thread safe for what you need.

Actually, even though a HashMap is not synchronized, it is also thread safe for what you need. The HashMap class is thread safe provided that no thread modify the structure of the map -- meaning adding or deleting items. Changing items are fine. And using it in a read-only fashion is definitely fine.

Henry
[ November 01, 2006: Message edited by: Henry Wong ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!