Our requirement is to download files form FTP server which we used a download files in sequential manner one after another which is taking huge time. Sequential code: for(String mediaValue: generatedMediaTypes) { // Logic here is getting the user selected files from Ui and keep it in string array str try { ddownloadMultipleNavDbs(str[i]),uniqueID); //now we download all the files here with downloadfile logic with help of unique id we are a folder by that name and keep all this files in that folder } catch (Exception ex) { logger.error(ex.getMessage()); } } After downloading all files into uniqueID folder now i zip and send to client by downloadZip(request,uniqueID): public void downloadZipFile (HttpServletResponse response, String suuid) throws IOException { try { ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); File loadableFolder = new File(uniqueID); String timeStamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()).toString().replaceAll( "-", "_").replaceAll(" ", "_").replaceAll(":", "_"); response.setHeader( "Content-Disposition", "attachment; filename=" + "File" + timeStamp.substring( 0, timeStamp.indexOf(".")) + ".ZIP"); File[] loadableMedias = //here we get the files from that uinqueID folder ZipUtil.addFilesToZipStream(Medias, Folder, zipOutputStream); zipOutputStream.close(); response.flushBuffer(); response.getOutputStream().flush(); response.getOutputStream().close(); } It works perfectly fine in above code. When i used executorservice for downloading files in parrallel executorService.submit(new myThread(str[i]),uniqueID); am facing error getOutputStream() has already been closed can anyone please explain me why am facing this error. Why we face this error and how to resolve it? | 0 |