I have a swing application that is quite slow to start up because it has to load a thousand pictures into the GUI. It takes 10 seconds to start up.
It is a single thread application, how could I code multithread to speed up the task? The following code is in a for loop of 1000 iterations.
ImageIcon icon = new ImageIcon(Files.readAllBytes(coverFile.toPath()));
// ImageIcon icon = createImageIcon(coverFile);
JLabel label = null;
if (coverCount % 2 == 0) {
label = createLabel(coverFile, movieFile, icon, SwingConstants.LEFT);
} else {
label = createLabel(coverFile, movieFile, icon, SwingConstants.CENTER);
}
box.add(label);
The images are being loaded and put into a Box sequentially. I have two difficulties if I want to do it multithread
- How does a thread return value to parent
- How to achieve non-blocking call back which add the image to the box sequentially
Thank you.