Question on multiThread

hi,

here're two sample code for singlethread and multithread.

but seems later will got time out exception.

really appreciate it if any help!

//single thread

import java.net.*;

import java.io.*;

class threadTest6 extends Thread

{

public static void main(String args[])

{

for(int i=0;i<100;i++)

{

try

{

URL url=new URL("http://www.siphrd.com/company/JobReader.php?com="+i);

URLConnection urlconnection=url.openConnection();

urlconnection.connect();

}

catch(Exception e)

{

ex++;

System.out.println(ex);

System.out.println(e);

}

}

}

private static int ex=0;

}

//multithread

import java.net.*;

import java.io.*;

class threadTest5 extends Thread

{

public static void main(String args[])

{

for(int i=0;i<1000;i++)

{

detail=new getDetail(i);

detail.setPriority(Thread.NORM_PRIORITY);

detail.start();

}

}

static class getDetail extends Thread

{

private int pageIDNum;

public getDetail(int t)

{

super("getDetail"+t);

pageIDNum=t;

}

public void run()

{

try

{

URL url=new URL("http://www.siphrd.com/company/JobReader.php?com="+pageIDNum);

URLConnection urlconnection=url.openConnection();

urlconnection.connect();

sleep(100);

}

catch(Exception e)

{

ex++;

System.out.println(ex);

System.out.println(e);

}

}

}

private static int ex=0;

private static getDetail detail;

}

[1714 byte] By [carla] at [2007-10-2 4:23:34]
# 1

You are trying 1000s of pages in the same time this may caouse a heavy network traffic and as a result a delay and then timeouts.

tyy with a less number of parreral downloads for example 3 downloads

and the same time read the input and close the streems dont just connect and forget

LRMKa at 2007-7-15 23:51:06 > top of Java-index,Java Essentials,New To Java...
# 2
Yeah you really shouldn't be trying this out unless you're just hitting your own website. 1000 requests coming at almost the same time is a form of DoS attack.
tjacobs01a at 2007-7-15 23:51:06 > top of Java-index,Java Essentials,New To Java...
# 3
ADVICE: when you post code please post them within code tags
LRMKa at 2007-7-15 23:51:06 > top of Java-index,Java Essentials,New To Java...
# 4
thanks, everyone.but i really need read info on these pages, and using single thread really cost too much time.anyone knows how to solve this?thanks in advance!
carla at 2007-7-15 23:51:06 > top of Java-index,Java Essentials,New To Java...