dcsimg
Number of threads generated is not tye desired number
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sopaan_Sinha
Posted On:   Thursday, May 31, 2001 02:12 AM

Dear Sir Actually i m working on Load Tester .The main aim of load tester is to simulate the number of hits to a given server. now the problem is that suppose there r n threads and each thread in turn generate m requests then accordinlt n*m requests r being sent to server and i should get n*m web pages.But i m not getting n*m pages. The reason behind this is URLStream which is i m opening up to read the web pages. So please suggest what should i do. here is the relwevant code. ________________________________________________________________ import java.net.*; import java.util.*; import java.io.*; import java.util.HashMap; class ThreadGenerator extends Thread //imple   More>>

Dear Sir

Actually i m working on Load Tester .The main aim of load tester
is to simulate the number of hits to a given server.
now the problem is that suppose there r n threads and each thread in turn generate m requests then accordinlt n*m requests r being sent to server and i should get n*m web pages.But i m not getting n*m pages.
The reason behind this is URLStream which is i m opening up to read the web pages.
So please suggest what should i do.
here is the relwevant code.
________________________________________________________________
import java.net.*;
import java.util.*;
import java.io.*;
import java.util.HashMap;
class ThreadGenerator extends Thread //implements Runnable
{
int iflag ;
InputForm form1;
int irequest1 ;
String stra ;
String name;
String value;
ThreadGenerator(int iflag1)
{
System.out.println("i m inside thread generator");
iflag = iflag1;
System.out.println(" the value of iflag "+iflag);
form1 = new InputForm();
// setDaemon(true);
irequest1=InputForm.irequest;//get the number of request of each thread
System.out.println(" the value of irequet1 "+irequest1);
}


public synchronized void doGet(int irequest1)
{
try
{
for (int j = 0;j <= irequest1 ; j++)
{
Set set = InputForm.hm.entrySet();//get a set of the entries
Iterator it = set.iterator();//get an iterator
stra = InputForm.strURL;
String ashu = stra+"?";
System.out.println(" the value of stra "+ashu);
while(it.hasNext())
{

Map.Entry me = (Map.Entry)it.next();
name=(String) me.getKey();
value= (String)me.getValue();
char ch ;
if(it.hasNext()) ch = '&';else ch = '
';
ashu+=(name+"="+value+ch);
System.out.println(" the value of ashu "+ashu.trim());
}
String search = "&=";
int i1 = ashu.indexOf(search);
int length = ashu.length();
String ashu1 = ashu.substring(0,i1);
System.out.println(ashu1);


URL hp = null;
try
{
hp= new URL(ashu1);

}
catch(MalformedURLException e)
{
System.out.println("+++++++++++++++++++++++++++asasasasasasasassasasasasasasasasasasasasasasasasasas");
}

InputStream input = null;
//while(!interrupted())
//{
URLConnection hpcon = hp.openConnection();

int len =hpcon.getContentLength();
if (len>0)
{
try
{

input = hpcon.getInputStream();
InputStreamReader input1 = new InputStreamReader(input);
BufferedReader in = new BufferedReader(input1);
/* wait();
try
{
Thread.sleep(5);
}
catch(InterruptedException e)
{
}*/
}
catch(FileNotFoundException exception)
{
}
catch(Exception exception)
{
//in.close();
InputStream err = ((HttpURLConnection)hpcon).getErrorStream();
//if(err == null) throw exception;
}
int i = len;
int c = 0;
System.out.println("%%%%%%%%%%%%((((((((())))))))))))))))))))###############");
while (!interrupted()&&((c=input.read())!=-1) && (--i >0))
{
System.out.print((char) c);
// notifyAll();
}

input.close();
}
else
{
System.out.println("no content available");
//System.out.println(s);
}
//}//while

}//for
}//try
catch(IOException e)
{
System.out.println("the exception is"+e.getMessage());
}

}//doget

public void doPost(int irequest1)
{
try
{
for (int i = 0;i <= irequest1 ; i++)
{
String stra = form1.strURL; //get it from input form
System.out.println("++++++++++++++++++++++++"+stra);
URL url = new URL(stra);
//while(true)
// {
URLConnection urlcon1 = url.openConnection();
urlcon1.setDoOutput(true);
PrintWriter out = new PrintWriter (urlcon1.getOutputStream());
Set set = form1.hm.entrySet();
Iterator i1 =set.iterator();
InputStream input = null;
String ashu1 = "";
while(i1.hasNext())
{
Map.Entry me = (Map.Entry)i1.next();
name = me.getKey().toString();
value = me.getValue().toString();
char ch ='
';
if(i1.hasNext()) ch='&'; else ch ='
';
ashu1+= (name + "=" + URLEncoder.encode(value)+ ch);
System.out.print(name + "=" + URLEncoder.encode(value)+ ch);
// System.out.print("(((((((((((((((((()))))))))))))))"+ashu1);
}
// System.out.print("(((((((((((((((((()))))))))))))))"+ashu1);
String search = "&=";
int i11 = ashu1.indexOf(search);
System.out.println("+++++++++++++++++++++++++++++"+search);
int length = ashu1.length();
String ashu11 = ashu1.substring(0,ashu1.lastIndexOf(search));
System.out.println("*******************"+ ashu11);
out.print(ashu11);

System.out.println(ashu11);
int len =urlcon1.getContentLength();
if (len>0)
{
System.out.println("============CONTENTS=====================
");
try
{
input = urlcon1.getInputStream();
}


catch(FileNotFoundException exception)
{
InputStream err = ((HttpURLConnection)urlcon1).getErrorStream();
if(err == null) throw exception;
}

int i5 = len;
int c = 0;
while (((c=input.read())!=-1) && (--i5 >0))
{
System.out.print((char) c);
}

input.close();
}//if of on the url connectivity
else
{
System.out.println("no content available");
//System.out.println(s);
}//else of no url connectivity
// }//while
}//for
}//try
catch(IOException e)
{
System.out.println("the exception is"+e.getMessage());
}
}//dopost



public void run()
{
InputForm frm8 = new InputForm();
int nrequest = frm8.irequest;
System.out.println("the value of request in run is "+nrequest);
switch(iflag)
{
case 1: doGet(nrequest);
break;

case 2: doPost(nrequest);
break;

default: break;
}

}

}

   <<Less
About | Sitemap | Contact