By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,805 Members | 1,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,805 IT Pros & Developers. It's quick & easy.

Downloading more than one file in java Download Manager with ThreadPool

P: 28
I want to the user be able to download more than one Download in the DownloadManager.But it just allow one download process?What does cause it?

This is Main.java
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) throws MalformedURLException {
  2.  
  3.     System.out.println("Welcome to Download Manager.");
  4.         int i=0;
  5.         boolean newDownload=true;
  6.         URL[] url =new URL[100] ;
  7.         String s1,s2,s3;
  8.         DownloadManagerSystem dms=new DownloadManagerSystem();
  9.         while(newDownload){
  10.             System.out.println("Enter a URL.");
  11.             Scanner scan= new Scanner(System.in);
  12.             s1=scan.nextLine();
  13.             System.out.println(s1);
  14.             url[i]= new URL(s1);
  15.             dms.addNewDownload(url[i]);
  16.             i++;
  17.          System.out.println("Do you want to add new URL:YES or NO");
  18.  
  19.          Scanner scan2= new Scanner(System.in);
  20.  
  21.          s2=scan2.nextLine();
  22.          if(s2=="YES"){
  23.               newDownload=true;
  24.           }
  25.           else
  26.           {
  27.               newDownload=false;
  28.  
  29.           }
  30.  
  31.         }
  32.     }
  33.  
  34.  
DownloadManager.java:
Expand|Select|Wrap|Line Numbers
  1.  private int threadPoolSize=10;//Limiting the number of working threads;
  2.  
  3.         private Download[] downloads;
  4.  
  5.         private ExecutorService tpes;
  6.         private int id=0;
  7.  
  8.         public void  createThreadPool() throws MalformedURLException{
  9.  
  10.             tpes= Executors.newFixedThreadPool(threadPoolSize);
  11.  
  12.           }
  13.         public void addNewDownloadToPool(URL url){
  14.                 downloads[id] = new Download(url,id);
  15.                 System.out.println("Download"+id+" is added to downloads list");
  16.                 tpes.execute(downloads[id]);
  17.                 id++;
  18.                 tpes.shutdown();
  19.         }
  20.  
  21.         public DownloadManager() throws MalformedURLException {
  22.  
  23.                 this.downloads = new Download[noOfDownloads];
  24.                 createThreadPool();
  25.        }    
  26.  
  27.  
  28.  
Apr 19 '13 #1

✓ answered by r035198x

Don't use == to compare Strings. Use the equals method instead.

Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
Don't use == to compare Strings. Use the equals method instead.
Apr 19 '13 #2

P: 28
@r035198x Thank you very much.It solved my question
Apr 19 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.