1

i have an old java applet (not written by me) that needs better peroformance.

I use allot of:

getToolkit().getImage(imageURL)

My problems with this are:

  1. It seams images will loaded one by one and not parallel

  2. The request have all the http keep-alive flag but for each image it opens a new tcp connection. And never close the connections.

Is there a solution to process images parallel with use http keep-alive function?

A short example, hwo the app work:

public class test 
{
    Map<String, URL> urlList = new HashMap<String, URL>();
    urlList.put("test", "/test.jpg"); 
    urlList.put("grrr", "/grrr.jpg");    
    urlList.put("htutz", "/htutz.jpg"); 
    urlList.put("fsdfgf", "/fsdfgf.jpg"); 
    urlList.put("fdgsfd", "/fdgsfd.jpg"); 
    urlList.put("fdgtzt", "/fdgtzt.jpg"); 
    urlList.put("reterg", "/reterg.jpg"); 
    urlList.put("ssdfsfdgsfd", "/ssdfsfdgsfd.jpg"); 

    for (URL imageUrl: urlList) {
    {
        new ImageExample(imageUrl);
    }
}


public class ImageExample extends JApplet {
    Image image;

    public void ImageExample(URL imageUrl) {
        image = getToolkit().getImage(imageUrl);
    }

    public void paint(Graphics g) {
        g.drawImage(image, 20, 20, this);
    }

    @Override
    public void draw( Graphics g )
    {
       paint(g);
    }
}
2
  • 1
    How do you propose reading in an image in a "non-parallel" way? How is this even physically possible? Does the program re-read an image in each time it is needed? If so, and if the images are small enough, then one possible improvement is to keep the images in memory and re-use them rather than re-read them. But not knowing more about the program, it's hard to give specific recs. Apr 2, 2013 at 13:10
  • I like to process the images parallel, but it thems images will load in row. Please see new example. The target is to process this as fast as possible
    – GreenRover
    Apr 2, 2013 at 13:35

1 Answer 1

1

Create a new thread to load each image and terminate it when the image is loaded.

Like this you will load all the images simultaneously and not anymore image by image. (And also you will not block the ui thread)

(Since you will not use the cache)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.