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?