New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider using Guavas Mapmaker class #3
Comments
Using this in place of google maps? |
I meant instead of this : |
Avoid using Third party library for a simple map representation. Java has sufficient variants in the Collections Interface. |
And as for the synchronized part, that should only be needed if the same map will be accessed by more than one thread concurrently. |
@piyushghai highly disagree. If one knows whats going on under the hood, using an external library is better. I could have suggested use of http://square.github.io/picasso/, but I understand the goal of the project is to learn by experimentation. But at the same time I feel https://github.com/google/guava is a pretty standard library one should be aware of and use. P.S +1 for suggesting use of ReentrantLock lock, but it is lighter compared to what ? Or did you mean a custom synchronization scheme could be made, 'which' is lighter (eg. lock on writes, don't lock on reads etc.) Collections.synchronizedMap, locks the 'whole' map which is quite wasteful. |
@Dexteroo7 If one knows what's going under the hood, then one can code it as well. Libraries are useful if they can abstract what's going under the hood and hence make life easier. Third party libraries should be used only if there is no native solution available. They also have their own memory footprint on the app. Reentrant lock is a lightweight lock, which is faster than synchronizing every access to the map, which is what Collections.synchronizedMap returns. The use case depends upon what one's requirements are. |
this https://code.google.com/p/guava-libraries/wiki/PhilosophyExplained Lets agree to disagree over the use of Guava. I use it amply in any Java related project I undertake :) |
Everyone has a different view point :) . I prefer using what Java provides off the blocks. If it lacks something, one should try to implement it first before using a custom library. Makes for a good learning as well shows you the limitations of the language |
Instead of synchronizing over the whole map, which is quite unnecessary in most cases use a ConcurrentMap instead. Guava has a great mapMaker utility.
eg. new MapMaker().weakKeys().makeMap()
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/MapMaker.html
The text was updated successfully, but these errors were encountered: