wood burning stoves 2.0*
The moose likes Java in General and the fly likes Linked Hash Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Linked Hash Map" Watch "Linked Hash Map" New topic
Author

Linked Hash Map

sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Hi All,
Thanks a lot in advance.

We are planning to use cache but we dont have any cache mechanism in the cache actually there should be some thing which provide the key, value and entry iteration that are consistent with an order of entry.
For this we came up with two approaches indexing that list and LisnkedHashMap.
But dont know what are disadvantages and overheads with LinkedhashMap.
Please give me some useful information and suggestions on this.

Regards,
Sree
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Look at this.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
If you need ordered key-value entries, then I think LHM it is simply the most natural choice for you (as far as Java is concerned). There may be some collection implementations that provide better performance, but frankly, I doubt it would be more than a marginal difference. One thing that might be significant in your case is that LHM is not synchronized. However, you may always use Collections#synchronizedMap() to enforce it. I looked in java.util.concurrent package, but haven't found ordered concurrent map implementation.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi,

A LikedHashTable would be synchronized too right?

Cheers,
Raj.
Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
I'm afraid there is no such class in the Java API (at least I never heard of it ). There is java.util.Hashtable and java.util.concurrent.ConcurrentHashMap (which are quite similar, with the latter being a bit faster for some operations), but as far as I know, neither of them supports element ordering, which is one of Sreedhar's requirements.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Well, you can always wrap your LinkedHashMap using java.util.Collections#synchronizedMap


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Originally posted by Sagar Rohankar:
Look at this.
Did you actually look at it? All the information you require was there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Linked Hash Map
 
Similar Threads
Want help for -instance-cache
taglib in Web.xml - Just for backward compatibility?
Old request data is still there.
Use of ReferenceQueue, WeakReference etc
cache usage = "read-only "