mrblah
mrblah

Reputation: 103507

creating multiple threads to upload to s3

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?

Upvotes: 1

Views: 3097

Answers (2)

alphazero
alphazero

Reputation: 27224

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 ;)]

Upvotes: 8

bmargulies
bmargulies

Reputation: 100050

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

Upvotes: 2

Related Questions