•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 361,899 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,407 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 3818 | Replies: 0
![]() |
•
•
Join Date: Mar 2005
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
i have a jsp program which use to download some files from the internet. i try to make it into multi-threading download. but at the end it still run in single thread.Do i need to use java bean? please help me. Thanks.
<%@ page import="java.io.*"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLConnection"%>
<%
String inStr="http://hgdownload.cse.ucsc.edu/goldenPath/hg17/vsMm5/axtNet/chr";
URL m_URL = null;
URLConnection m_URLConn = null;
boolean m_bOk = true;
Thread thread1 = new Thread("T1");
Thread thread2 = new Thread("T2");
thread1.start();
thread2.start();
boolean thread1IsAlive = true;
boolean thread2IsAlive = true;
do {
if(thread1IsAlive && !thread1.isAlive())
{
thread1IsAlive = false;
try
{
//thread1.join();
int x=1;
String x_str = "";
do{
x_str = Integer.toString(x);
if (x==23) x_str = "X";
else if (x==24) x_str="Y";
m_URL = new URL(inStr+x_str+".axt.gz");
m_URLConn = m_URL.openConnection();
URLConnection uc = m_URL.openConnection();
//InputStream in = new FileInputStream(uc.getInputStream());
InputStream in = new BufferedInputStream(uc.getInputStream());
ByteArrayOutputStream bs = new ByteArrayOutputStream(9999);
int i;
String sFile = "c:\\downloadChr\\mhuman\\chr"+x_str+".axt.gz";
System.out.println("Getting file " + sFile);
File of = new File(sFile);
while(-1 != (i = in.read()))
bs.write(i);
in.close();
byte bt[] = bs.toByteArray();
FileOutputStream fos = new FileOutputStream(of);
fos.write(bt);
fos.close();
System.out.println("Thread 1 is dead.");
} while(x++ <12); //do
}//try
catch(Exception e)
{
e.printStackTrace();
}
}
if(thread2IsAlive && !thread2.isAlive())
{
thread2IsAlive = false;
try{
//thread2.join();
int x=13;
String x_str = "";
do{
x_str = Integer.toString(x);
if (x==23) x_str = "X";
else if (x==24) x_str="Y";
m_URL = new URL(inStr+x_str+".axt.gz");
m_URLConn = m_URL.openConnection();
URLConnection uc = m_URL.openConnection();
//InputStream in = new FileInputStream(uc.getInputStream());
InputStream in = new BufferedInputStream(uc.getInputStream());
ByteArrayOutputStream bs = new ByteArrayOutputStream(9999);
int i;
String sFile = "c:\\downloadChr\\mhuman\\chr"+x_str+".axt.gz";
System.out.println("Getting file " + sFile);
File of = new File(sFile);
while(-1 != (i = in.read()))
bs.write(i);
in.close();
byte bt[] = bs.toByteArray();
FileOutputStream fos = new FileOutputStream(of);
fos.write(bt);
fos.close();
System.out.println("Thread 2 is dead.");
} while(x++ <24); //do
}//try
catch(Exception e)
{
e.printStackTrace();
}
}//if
} while(thread1IsAlive || thread2IsAlive);
%>
<meta HTTP-EQUIV="REFRESH" content="1; url=http://localhost:8080/examples/jsp/HMC/HTML/downloaded.htm">
<%@ page import="java.io.*"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.net.URLConnection"%>
<%
String inStr="http://hgdownload.cse.ucsc.edu/goldenPath/hg17/vsMm5/axtNet/chr";
URL m_URL = null;
URLConnection m_URLConn = null;
boolean m_bOk = true;
Thread thread1 = new Thread("T1");
Thread thread2 = new Thread("T2");
thread1.start();
thread2.start();
boolean thread1IsAlive = true;
boolean thread2IsAlive = true;
do {
if(thread1IsAlive && !thread1.isAlive())
{
thread1IsAlive = false;
try
{
//thread1.join();
int x=1;
String x_str = "";
do{
x_str = Integer.toString(x);
if (x==23) x_str = "X";
else if (x==24) x_str="Y";
m_URL = new URL(inStr+x_str+".axt.gz");
m_URLConn = m_URL.openConnection();
URLConnection uc = m_URL.openConnection();
//InputStream in = new FileInputStream(uc.getInputStream());
InputStream in = new BufferedInputStream(uc.getInputStream());
ByteArrayOutputStream bs = new ByteArrayOutputStream(9999);
int i;
String sFile = "c:\\downloadChr\\mhuman\\chr"+x_str+".axt.gz";
System.out.println("Getting file " + sFile);
File of = new File(sFile);
while(-1 != (i = in.read()))
bs.write(i);
in.close();
byte bt[] = bs.toByteArray();
FileOutputStream fos = new FileOutputStream(of);
fos.write(bt);
fos.close();
System.out.println("Thread 1 is dead.");
} while(x++ <12); //do
}//try
catch(Exception e)
{
e.printStackTrace();
}
}
if(thread2IsAlive && !thread2.isAlive())
{
thread2IsAlive = false;
try{
//thread2.join();
int x=13;
String x_str = "";
do{
x_str = Integer.toString(x);
if (x==23) x_str = "X";
else if (x==24) x_str="Y";
m_URL = new URL(inStr+x_str+".axt.gz");
m_URLConn = m_URL.openConnection();
URLConnection uc = m_URL.openConnection();
//InputStream in = new FileInputStream(uc.getInputStream());
InputStream in = new BufferedInputStream(uc.getInputStream());
ByteArrayOutputStream bs = new ByteArrayOutputStream(9999);
int i;
String sFile = "c:\\downloadChr\\mhuman\\chr"+x_str+".axt.gz";
System.out.println("Getting file " + sFile);
File of = new File(sFile);
while(-1 != (i = in.read()))
bs.write(i);
in.close();
byte bt[] = bs.toByteArray();
FileOutputStream fos = new FileOutputStream(of);
fos.write(bt);
fos.close();
System.out.println("Thread 2 is dead.");
} while(x++ <24); //do
}//try
catch(Exception e)
{
e.printStackTrace();
}
}//if
} while(thread1IsAlive || thread2IsAlive);
%>
<meta HTTP-EQUIV="REFRESH" content="1; url=http://localhost:8080/examples/jsp/HMC/HTML/downloaded.htm">
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
Similar Threads
- jsp and mysql (JSP)
- how to use jsp and tomcat (JSP)
- Can't run JSP in Browser (JSP)
- Word.doc upload using JSP (Java)
- Can't run JSP in Browser (Web Browsers)
- JSP and Oracle (JSP)
Other Threads in the JSP Forum
- Previous Thread: JAVA help
- Next Thread: I think I'm going to cry...


Linear Mode