Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:43:05+00:00 2026-06-18T02:43:05+00:00

Like a hybrid of ConcurrentHashMap and ConcurrentLinkedQueue. Here is my requirements: I need a

  • 0

Like a hybrid of “ConcurrentHashMap” and “ConcurrentLinkedQueue”.

Here is my requirements:
I need a asynchronous updated cache system. That means I wrap every entity before set it into memcache. There is a timestamp in the warpper which indicate when its content should expire. Each request from front side would fetch data from memcache, and if the warpper shows expiration, an update event would be generated and put into a concurrentLinkedQueue, then waiting to be updated asynchronously.
The problem is: I don’t want to update an entity more than once in vain. Before adding an event to the queue, I wish to find a way to make sure there is no event for the same entity in the queue already.

Is that OK if I do it in these ways?

1,Create a warpper Class, it contains a hashMap and a linkedList in it. All its method is synchronized:

public synchronized boolean add(String key,Object value){
    if(hashMap.containsKey(key)){
        return false;
    }else{
        hashMap.put(key,value);
        return linkedList.offer(value);
    }
}  

I believe this solution would be extremely slow.
Maybe It’s just like Collections.synchronizedMap(new LinkedHashMap()).

2,Just use a concurrentHashMap. If I need “poll” action, iterator an element from it.

public Object poll(){
    Collection valueColl = concurrentHashMap.values();
    if(valueColl.isEmpty()){
        retrun null;
    }
    return valueColl.get(0);
}  

The action concurrentHashMap.values().get(0) is slow or not?

3,Looking into the source code of “ConcurrentHashMap” and “ConcurrentLinkedQueue”, then write an “ConcurrentUniqueLinkedQueue” if possible.
This looks a little hard for me for the moment.

so, how would you guys say?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:43:07+00:00Added an answer on June 18, 2026 at 2:43 am

    I don’t imagine you want to discard the latest updates. Perhaps you are making it more complicated than it needs to be.

    public void add(K key, V value) {
        concurrentMap.put(key, value);
        queue.add(key);
    }
    
    public V poll() {
        for(K key; (key = queue.take()) != null;) {
            V value = concurrentMap.remove(key);
            if (value != null)
               return value;
            // value will be null if it's a duplicate so ignore and look for more.
        }
        return null;
    }
    

    This will give you the latest value for key in queued order. It doesn’t need any locking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hybrid ASP.NET MVC application, and I'd like to test that the
I need to display data that will be hybrid hard-coded strings and data from
Is there a std container in c++ that acts like a hybrid between a
The RegExp.exec function returns something that looks like a hybrid array . It's an
Lasty, I tried to implements an hybrid structure in Java, something that looks like:
I've got a HTML5 hybrid app that I want to wrap in trigger.io for
I am new to this iPhone development.I would like to create a hybrid application
Like i sayed in the title, i need to build an array and change
Like a person asked here (but his solutions as to call a nother function)
I am using requireJS for my hybrid app . Now I need to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.