Iam using the code below to upload images to a remote server. When I use below, it uploads all the images at once to the 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 future objects to the future list, immediately returning from runnable (without waiting in runnable until all images have finished loading (background loading processing is performed)
But whenever I uncomment below the line above the code, after successfully loading each 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 something wrong in my code, and is it normal to accept a remote connection to the server more at a time or any download on the server? How to load images using java parallel programming? Please give us a guide?
Do the same functions submit() and execute() ?
source share