31. Is it better to synchronize
critical section of getInstance() method or whole getInstance() method?
Critical section because if we
lock whole method than every time someone who calls this method will have to
wait even though we are not creating any object.
32.Which one would be easy to write? synchronization code for 10
threads or 2 threads?
Both will have same complexity because synchronization code is independent
of no. of threads.
33. How does WeakHashMap work?
Although its working is same as like a normal HashMap ,it uses WeakReference for keys, which means if the key object doesn't have any reference then both key/value mapping will become eligible for garbage collection.
Although its working is same as like a normal HashMap ,it uses WeakReference for keys, which means if the key object doesn't have any reference then both key/value mapping will become eligible for garbage collection.
34. What is a difference
between WeakReference and SoftReference?
SoftReference can delay it until JVM absolutely need memory (even though it cannot prevent GC). But WeakReference becomes eligible for garbage collection as soon as last strong reference is lost.
SoftReference can delay it until JVM absolutely need memory (even though it cannot prevent GC). But WeakReference becomes eligible for garbage collection as soon as last strong reference is lost.
35. Does not overriding
hashcode() method has any performance implication ?
Yes of course. Hashcode function will result in frequent collision in HashMap which eventually increase time for adding an object into Hash Map.
Yes of course. Hashcode function will result in frequent collision in HashMap which eventually increase time for adding an object into Hash Map.
No comments:
Post a Comment