473,669 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Downloading more than one file in java Download Manager with ThreadPool

28 New Member
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
2 1601
r035198x
13,262 MVP
Don't use == to compare Strings. Use the equals method instead.
Apr 19 '13 #2
notfound
28 New Member
@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
3217
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 download page that uses a file download component. The file downloads fine, except that Internet Explorer refuses to browse to a different page while the file is downloading! I don't understand why it does that and I don't know how to fix this...
1
2921
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 (_uid,_psswd); wReq.Timeout = 6000000; WebResponse wRes = wReq.GetResponse(); Stream wOutput = wRes.GetResponseStream(); BinaryReader br = new BinaryReader (wOutput);
2
4719
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 that can handle resuming downloads. Any ideas? -djm
4
1281
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 to a <Select> tag as a webcontrol dropdownlist. Here's what's happening: I have a page inside a frame. On it are a couple of links and a <Select> tag. The selection list has nothing to do with the links and it works fine -- usually.
2
1830
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 downloading this file is being appended to the end of the file. So I am accidently modifiying every file that is placed in the database. What follows is my code for uploading and downloading a file, minus the sql code to insert/retrieve the data...
1
2070
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 any page from the server while downloading. If I try to call a single page while downloading a file then the page request goes time out and the server then closes the existing download stream and the client doestn't throw any exception. So many a...
3
2786
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 any page from the server while downloading. If I try to call a single page while downloading a file then the page request goes time out and the server then closes the existing download stream and the client doestn't throw any exception. So many a...
1
2077
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 problem I have is that I have two network adapters connected to different internet connections now I want to use both connections when I download files from rapidshare. I have looked at the options of dual Wan routers and for the price I don't...
0
1066
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 my download manager. The MSDN http://support.microsoft.com/kb/327865 guides to use The COM object to achieve this .As I am new to COM object, I am not able understand the stuff.is there any interface like IDownloadManager in C# ? .Please help me...
1
3321
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
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.