java - When i need to use hashMap because it is not synchronized -


i know hashtable synchronized, whereas hashmap not.

as per knowledge synchronization means accessing object @ time 1 thread.

so there no problem while using hashtable. in project using hashmap. used in many places. till did not problem hashmap.

so when synchronization concept come picture(i.e using hashmap).

can use hashmap in places using hashtable?

can use hashtable in places using hashmap?

so there no problem while using hashtable

not - in situations, hashtables require external synchronization (for example while iterating).

when synchronization concept come picture (i.e using hashmap)?

if have class holds hashmap:

public class someclass {     private map map = new hashmap(); } 

and access map several threads, might unexpected behaviour , should use adequate synchronization.

as long access map single thread or local variable within method, fine.

can use hashmap in places using hashtable?

cf. above: yes if map not accessed several threads.

can use hashtable in places using hashmap?

yes always, although less efficient performance-wise.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -