• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 76426
366
  • 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.
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic