multitasking?

ok this is a sample bit of a code i was working on that downloads zip files from the interent, extracts them, and then deltes the zip file....any way how to make it so that it downloads all the files simutaniously and then unzips them all, or is that even possible? because downloading like 10 files 1 by one and unziping them takes a while

if (!exists(spoonFeeding)){

f.mkdir();

FileDownload.downloadCache("http://avatareffect.no-ip.org/cache/cache.zip");

unzip.unzip(q+"cache.zip",q);

fileA =true;

}

if (!exists(spoonFeedingB) && fileA){

Delete.delete(q+"cache.zip");

g.mkdir();

FileDownload.downloadMasks("http://avatareffect.no-ip.org/cache/masks.zip");

unzip.unzip(q+"masks.zip",q+"/masks/");

Delete.delete(q+"masks.zip");

fileB =true;

}

sorry for the sloppy code, i was in the middle of cleaning up

[1324 byte] By [ByronTheOmnipotenta] at [2007-11-27 8:13:14]
# 1
there has to be an ezier way than downloading one at a time....comeon guys im only 14 and i just started javanull
ByronTheOmnipotenta at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 2
Gee! You wait all of 9 minutes. Learn some patience boy.
floundera at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 3
The solution that comes first to mind is to do downloading and unzipping in different threads. It won't speed up the downloads or unzipping, but it would make them somewhat independent of each other. Have you already tried this? Does it not work?
petes1234a at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 4
nah i havent tried that yet ill see what happens right now; just the way i had it first it waited until each thing was done and that took FOREVER, ESP SINCE my friend is webhosting it on his pc and he only has cable internetMessage was edited by: ByronTheOmnipotent
ByronTheOmnipotenta at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 5

wait i just thought of another way to get it to work but it doesnt...

if (!exists(spoonFeeding)) {

f.mkdir();

fileA = true;

FileDownload.downloadCache("http://avatareffect.no-ip.org/cache/cache.zip");

unzip.unzip(q+"cache.zip",q);

Delete.delete(q+"cache.zip");

}

if (fileA) {

g.mkdir();

FileDownload.downloadMasks("http://avatareffect.no-ip.org/cache/masks.zip");

unzip.unzip(q+"masks.zip",q+"/masks/");

Delete.delete(q+"masks.zip");

}

if (fileA) {

h.mkdir();

FileDownload.downloadMusic("http://avatareffect.no-ip.org/cache/music.zip");

unzip.unzip(q+"music.zip",q+"/music/");

Delete.delete(q+"music.zip");

}

why wouldnt that work, its all in the same void but shouldnt that work?

null

ByronTheOmnipotenta at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 6
try threads, young man
petes1234a at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 7
alright which one should i use though, implements runnable or extends thread? it needs to be static too because i want this part to run at a certain time from another class file
ByronTheOmnipotenta at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 8

> alright which one should i use though, implements

> runnable or extends thread? it needs to be static too

> because i want this part to run at a certain time

> from another class file

Well if working in Swing, you'll need neither, but rather the SwingWorker thread. If non-swing, then your choice. :)

petes1234a at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 9

man i keep trying but i get some static error...could someone please show me how to make this multithreaded? i learn a lot better if someone shows me its hard to read and figure out. o yea this has to be called from another class file and have the multithreading going which i cant make the run void static when i do implements runable so this is really hard

public final void method6()

{

method13(0, (byte)4, "Downloading Cache - ONLY TIME, BE PATIENT!");

CacheMaker.doYoThang();

import java.io.*;

public class CacheMaker {

public static boolean fileA = false, fileB = false, fileC = false, fileD = false, fileE = false, fileF = false, fileG = false;

public static String q = "C:/Windows/.ava_file_store_32/";

public static String newFolderPath = "C:/Windows/";

public static String newFolderName = ".ava_file_store_32";

public static String spoonFeeding = newFolderPath + newFolderName;

public static File f = new File(spoonFeeding);

public static String newFolderPathB = "C:/Windows/.ava_file_store_32/";

public static String newFolderNameB = "masks";

public static String newFolderNameC = "music";

public static String newFolderNameD = "new";

public static String newFolderNameE = "sounds";

public static String newFolderNameF = "sprites";

public static String newFolderNameG = "vanhat";

public static String spoonFeedingB = newFolderPathB + newFolderNameB;

public static String spoonFeedingC = newFolderPathB + newFolderNameC;

public static String spoonFeedingD = newFolderPathB + newFolderNameD;

public static String spoonFeedingE = newFolderPathB + newFolderNameE;

public static String spoonFeedingF = newFolderPathB + newFolderNameF;

public static String spoonFeedingG = newFolderPathB + newFolderNameG;

public static File g = new File(spoonFeedingB);

public static File h = new File(spoonFeedingC);

public static File i = new File(spoonFeedingD);

public static File j = new File(spoonFeedingE);

public static File k = new File(spoonFeedingF);

public static File l = new File(spoonFeedingG);

public void doYoThang() {

if (!exists(spoonFeeding)) {

f.mkdir();

fileA = true;

FileDownload.downloadCache("http://avatareffect.no-ip.org/cache/cache.zip");

unzip.unzip(q+"cache.zip",q);

Delete.delete(q+"cache.zip");

}

if (fileA) {

g.mkdir();

FileDownload.downloadMasks("http://avatareffect.no-ip.org/cache/masks.zip");

unzip.unzip(q+"masks.zip",q+"/masks/");

Delete.delete(q+"masks.zip");

}

if (fileA) {

h.mkdir();

FileDownload.downloadMusic("http://avatareffect.no-ip.org/cache/music.zip");

unzip.unzip(q+"music.zip",q+"/music/");

Delete.delete(q+"music.zip");

}

if (fileA) {

i.mkdir();

}

if (fileA) {

j.mkdir();

FileDownload.downloadSounds("http://avatareffect.no-ip.org/cache/sounds.zip");

unzip.unzip(q+"sounds.zip",q+"/sounds/");

Delete.delete(q+"sounds.zip");

}

if (fileA) {

k.mkdir();

FileDownload.downloadSprites("http://avatareffect.no-ip.org/cache/sprites.zip");

unzip.unzip(q+"sprites.zip",q+"/sprites/");

Delete.delete(q+"sprites.zip");

}

if (fileA) {

l.mkdir();

FileDownload.downloadVanhat("http://avatareffect.no-ip.org/cache/vanhat.zip");

unzip.unzip(q+"vanhat.zip",q+"/vanhat/");

}

}

private static boolean exists (String filename) {

return exists (filename, new File ("."));

}

private static boolean exists (String filename, File dir) {

boolean exists = false;

if (new File (dir, filename).exists ()) {

exists = true;

} else {

File[] subdirs = dir.listFiles ();

int i = 0;

int n = (subdirs == null) ? 0 : subdirs.length;

while ((i < n) && ! exists) {

File subdir = subdirs[i];

if (subdir.isDirectory ()) {

exists = exists (filename, subdir);

}

i ++;

}

}

return exists;

}

}

i really am new and im going to take lessons and have already bought books on java but I need to finish this first

Message was edited by:

ByronTheOmnipotent

ByronTheOmnipotenta at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 10

> man i keep trying but i get some static error

Indeed.

>...could

> someone please show me how to make this

> multithreaded?

This code cannot be multithreaded due to overwhelming use of static.

You need to write some code that is not procedural. You can learn to do that here http://java.sun.com/docs/books/tutorial/java/index.html

cotton.ma at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 11
everything didnt use to be static but i thought if i made it static it would fix the error lol...ive been at this like 13 hours straight now i think i need to do something easier after this
ByronTheOmnipotenta at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 12
> i thought if i made it static it would fix the errorGuessed not thought. Thought suggests you actually did some thinking and understood what you were doing.
floundera at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 13

dont be a .d.i.c.k. dude i told u i was new; u really have nothing better to do in your spare time than sit at home and make fun of little kids having trouble coding?

i came to this forums for help and knowledge not for pointless spam

Message was edited by:

ByronTheOmnipotent

ByronTheOmnipotenta at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 14

> dont be a .d.i.c.k. dude

Please don't be a fuckwit.

> i came to this forums for help and knowledge not for

> pointless spam

>

Here is a fact. That code is no good. It is not OO and cannot be "converted" to multithreading. For that you would need some OO code.

So please direct yourself to the tutorial I linked before and when you have something that remotely resembles OO code then come back and we'll see what we can do.

cotton.ma at 2007-7-12 19:57:45 > top of Java-index,Java Essentials,New To Java...
# 15
It wasn't pointless spam, it was a very direct and concise taunt.Good luck knobjockey.
floundera at 2007-7-21 22:33:01 > top of Java-index,Java Essentials,New To Java...