Reputation: 6433
If I have many queues and each has an unique ID, would a Hashtable of Queues be the way to go? I know it sounds strange that I'm asking this, but just wondering if there might be a better way for optimization.
Sorry for the lack of information. I'm basically storing queues of messages which are identified by the client id. The client will request to get messages from the server. In the case when the ack does not reach the server, the message still remains in the queue until the client makes another attempt to get the oldest message. The idea is to retain all the messages if the client fails to ack and to retrieve all messages in a FIFO manner.
Upvotes: 2
Views: 219
Reputation: 481
since java is statically typed, i would definitely use a hashtable... (that is, if we are talking about optimization)
Upvotes: 0
Reputation: 106401
The question doesn't provide any detail on what you want to do with this. And this is very important, because the usage pattern is critical in determining which data structure is going to be most efficient for your use case.
But I'd say that in the absence of other details, a HashTable of Queues sounds like a sensible choice, with the HashTable using the ID as a key and the corresponding Queue as a value.
Then the following operations will both be O(1) with very low overhead:
Which is probably the usage pattern you are going to be needing in most cases.....
Upvotes: 4