Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4005182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:21:48+00:00 2026-05-20T08:21:48+00:00

Iam using below code for uploading images on the remote server.When I use below

  • 0

Iam using below code for uploading images on the remote server.When I use below it is uploading all images cocurrently on remote server.

List<Future<String>> futureList = new ArrayList<Future<String>>();
ExecutorService execService = Executors.newFixedThreadPool(Images.size());
for (IImage image : Images) { 
  try {
    //execService.execute(lServerRequest.new uploadImages(image.getDataPath(),image.getDisplayName()));
    singleFuture = execService.submit(lServerRequest.new uploadImages(image.getDataPath(),image.getDisplayName()));
    //Log.d("","singleFuture -------"+singleFuture.get());
    futureList.add(singleFuture);
    Log.d("","futureList Size:"+futureList.size());
  } catch(Exception e){
    execService.shutdown();
  }

Whenever i used below code

   singleFuture = execService.submit(lServerRequest.new uploadImages(image.getDataPath(),image.getDisplayName()));
//Log.d("","singleFuture -------"+singleFuture.get());
    futureList.add(singleFuture);

adds all the future objects to futurelist immediately returning from runnable(not waiting in runnable until completion of uploading of all images(background uploading processing is going)

But whenever i uncommented below line in above code ,after successful uploading of every image it returns from runnable.

singleFuture = execService.submit(lServerRequest.new uploadImages(image.getDataPath(),image.getDisplayName()));
Log.d("","singleFuture -------"+singleFuture.get());
futureList.add(singleFuture);

is there anything wrong in my code and is it ok to take remote server connection more at a time or any load is on server?How to upload the images by using cocurrent programming java?Please give us guidance?

Do the submit() and execute() functions have the same effect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:21:48+00:00Added an answer on May 20, 2026 at 8:21 am

    When you call singleFuture.get() you are waiting for the operation to complete. So the loop won’t continue to execute next statement until this one returns a result.

    You need to submit your tasks in the first loop and after that, another loop should iterate over the results future.get() on your list to make it async

    From @andersoj’s answer;

    The Pool size should be something related to your CPU cores. Not the number of images you have in hand. Say if you have 2 cored CPU, a coefficient of 5 (just my guess of coefficient) for image uploading io time.

    POOL_SIZE = NUM_OF_CPU_CORE*coeffiecient;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the code below to save and restore the window position and
In the code below I am using a recursive CTE(Common Table Expression) in SQL
The code below is the code i am using. It works fine in thunderbird
If I am using a tree structure of nodes similar to the code below,
I am using the code snippet below, however it's not working quite as I
Using the code below, I am returning an nvarchar field from MS SQL 2005
I am trying to manipulate a string using Jython, I have included below an
I am using the program below to sort and eventually print out email messages.
I am using xcode 2.4.1 on tiger. When i do below everything is ok.
I am using SQL Server 2005. I have a table with a text column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.