Doing a background job and not stall whole applet
Ive been developing a 3D game. So far I was able to
- Download cache to clients computer
- Use the cache
Now. I have two engines, one for the main processing and the other for the graphics. For the gfx engine to work it needs the main engine to finish what its doing or specifically whatever it has started. So in case 3, which is the third case during startup is that it downloads a GIANT 100mb cache file. During this download the Applet seems to freeze. Thats the problem. The code for my downloader is as so (Please do not copy, make your own):
Code:
public SaveFile(String url, File file) {
try {
URL vs_site = new URL(url);
FileOutputStream out = null;
InputStream in = null;
try {
byte buf[] = new byte[4 * 1024]; // 4kb buffer
int read = -1;
in = vs_site.openStream();
out = new FileOutputStream(file);
while((read = in.read(buf)) != -1) {
out.write(buf, 0, read);
}
out.flush();
} finally {
if (in != null) in.close();
if (out!= null) out.close();
}
} catch (IOException ioe) {
System.err.println("Error Saving " + ioe);
}
}
So like i said durng step 3, it calls this procedure but the URL links to a 100MB file. And during the download the applet shows white. And as i also said the reason behind this is that the second this procedure starts the program has to complete it before the graphics engine gets a go.
~becool
Thanks