• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java Memory Model: A cache image data question, multithreaded.

 
Ranch Hand
Posts: 31
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From this quote, "Just save the images in memory and retrieve them from memory instead of the network when you need to."

If I create a Thread that has a Runnable in which downloads images and stores the image data in memory (variables within an Object), how can I reference the same Object from a different Thread to get the image data in memory?
 
Ranch Hand
Posts: 64
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure this is the best way to do it, but when you create your Runnable to go a gradually load images from the network, you can pass it an empty Map (or something similar). The class that's kicking off your runnable should keep a reference to the Map, and make it available to whatever other threads might want to get images.

Then, you can use the String path to the image as the key to see if an image is loaded into your Map cache before you try to go get it on the network independently.

Is that what you're looking for?
 
Todd Patrick
Ranch Hand
Posts: 31
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is definitely a very good idea and something that I will try today. Thank you.
 
Marshal
Posts: 80950
522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is too difficult a question for "beginning", so I shall move it.
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic