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??
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: