views:

96

answers:

2

I am uploading files to s3 using amazons s3 web service.

It takes about 1 second per file, is there a way I could fire up multiple threads to do this in parallel?

Say I have a method that does the upload call:

public void uploadToS3(string filename);

how can I call fire up 3 threads and each make this call?

+2  A: 

Please read the standard thread tutorial, or edit your question to explain what you need to know that's specific to s3?

bmargulies
+4  A: 

Wrap your function in a Runnable interface

public Runnable getS3UploadTask () {
   return new Runnable() {
       public void run() {
           uploadToS3();
       }
   };
}

and, then you can create as many threads as you please to execute the Runnable:

public void startS3Tasks(int workerCnt) {
    for(int i=0; i<workerCnt; i++) {
       new Thread(getS3UploadTask()).start();
    }
}

[Edit: of course, the above is only addressing your issue of "how to" and may be entirely irrelevant to the goal of improving uploads ;)]

perfect that is what I wanted to learn thanks!
mrblah