473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Downloading more than one file in java Download Manager with ThreadPool

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.

2 1592
r035198x
13,262 8TB
Don't use == to compare Strings. Use the equals method instead.
Apr 19 '13 #2
@r035198x Thank you very much.It solved my question
Apr 19 '13 #3

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

Similar topics

1
by: ASP Spam Fighter | last post by:
Hello all, I don't know how to get around this one... If anybody can help me with this problem, I would appreciate it very much. I've been trying to send a (large) file to the browser via a...
1
by: Rajiv Barik | last post by:
hi , I am trying to download a zip file from a http site using webResponse . here's the code WebRequest wReq ; wReq = WebRequest.Create(wUri ) ; wReq.Credentials = new NetworkCredential...
2
by: dan mcgraw | last post by:
We want to offer a 100 Mb file for download but are concerned over modem users who cannot finish the download. Is there any way to implement a download manager in JS? Looking for something simple...
4
by: Jeff Cooper | last post by:
There must be something I'm missing. No else else seems to have this issue -- at least I don't see it mentioned anywhere. (Also, my appologies for my earlier posts in which I mistakenly referred...
2
by: Ryan Taylor | last post by:
Hello. I am trying to upload a file and save it in a Sql Server 2000 database. This seems to be working fine. However, when I download the file from SQL Server, it appears that the page that is...
1
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
3
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
1
by: naza | last post by:
Before I start I would just like to say that I am totally new to programming so the things that I am going ask probally will sound basic and I might sound I bit ambitious in what I want to do. The...
0
by: PreethiParkavi | last post by:
Hi All, I am trying to develop a custom download manager for my website and I have partially succeed.The Problem is, When I download a file, The browser opens default download manager Instead of...
1
by: leenak | last post by:
I would like to implement a very simple download manager in Java to download a file from URL address. Thanks for all the help Leena
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.