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 493771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:26:12+00:00 2026-05-13T05:26:12+00:00

i’m creating a web page which contains a few dynamically generated images. in my

  • 0

i’m creating a web page which contains a few dynamically generated images.

in my page request handling i create all of the images and store them in a memory cache until they are subsequently requested by the browser.

public class CachedImage
{
    byte[] data;
    Date created;
}

currently, my image cache is essentially a HashMap<Integer, CachedImage>.

the problem is that the image generation takes time, and i’d like to start rendering the page before all of the images have finished generating.

so i’d like to generate the images in a Thread Pool and when requested, return the data if it’s ready or wait until the data is ready and then return.

can anyone come up with a tidy model for this mechanism?

the images are small, and i’m happy with the approach of caching the whole image in memory for now.

  • 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-05-13T05:26:12+00:00Added an answer on May 13, 2026 at 5:26 am

    While generating the page, choose a new unique identifier for each image that the page will display. This might be something simple like a number obtained by incrementing an AtomicInteger, or it might be something more sophisticated like a UUID to prevent users from guessing other users’ image URLs. Put these unique identifiers into the URLs that the client will use to retrieve the images.

    Once you’ve chosen the identifier for an image, construct a Callable that will generate and return the image, and submit it to a ThreadPoolExecutor to be run asynchronously. This gives you back a Future which can be used to retrieve the result. Save the Future in a map, with the image’s identifier as the key.

    Later, when the client requests the image, you can take the image identifier and look it up in the map to find the associated Future object. Calling get() on the Future will return the image, waiting for the generator to finish if necessary. (If the requested identifier isn’t found in the map, return a 404 error.)

    To avoid filling up the server’s memory with old images, you’ll probably want to discard them after a few minutes. To do that, each time you create a task and store its Future into the map of available images, you can put a task into a DelayQueue that’ll remove the entry from the map after some suitable delay. Use a daemon thread to take items from this queue and act on them, in a loop.

    It’d also be a good idea to call cancel(true) on the Future when removing it from the map, in case the generator was still running for some reason. (Otherwise it would continue running even though the image will no longer be accessible anyway.)

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.