Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

"Image Fetcher" Threads??

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need help! Has anyone ever heard of 'image fetcher' threads??

I have a java program, which, during its initialization, creates
2 different objects - let's call them object A and B.

Each of these objects contains a very simple loop which
loads a large number of ImageIcons. The reference to each
ImageIcon is stored in a simple list (an ArrayList).

I'm loading each image from the disk using this kind of code:


URL url = ClassLoader.getSystemResource(fileName);
ImageIcon image = new ImageIcon(url);
list.add(image)


Now object A loads about 60 jpeg images, and object B loads
about 200 jpeg images. The total amount of memory only
amounts to about 4 megabytes.

But, for some reason, when these 2 objects are created,
I'm getting some exceptions thrown. For example:


Exception in thread "Image Fetcher 3" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Image Fetcher 2" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space


What are these threads? Why am I getting these exceptions?

The odd thing is that if I create just object A OR object B, and not both,
I don't get these exceptions. So what should I be doing??

Any help would be greatly appreciated.


David.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to speed up image loading, Java starts a Thread for each request. This is just like a web browser that runs a number of requests for the various components of a web page.

If you are going to have a huge number of requests, you need to manage the requests to only do a few at at time.
It has been a while since I have done this sort of thing, but it looks like ImageIcon has a getImageLoadStatus() method.
Bill
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!