Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

JSP timing program and all hit the URL at the same time


I am trying to create some kind of JSP timing program and all hit the URL at the same time. So, I need an automated load testing tool. Does anyone has any idea?

BTW, this question is related the following question.

  • 5
  • 3
1 Solution
WebLoad from Radview http://www.radview.com/default.asp. You can download an evaluation version.

Or for a bigger enterprise system http://www.mercury.com/us/products/quality-center/functional-testing/winrunner/
Or you write it yourself using HttpUrlConnection
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

dkim18Author Commented:
All the links that you have provided me are too huge for this assignment. I am sure this isn't supposed to be a big project.
Would you mind reading my original question and advise me best solution for me? Actually, I am not even sure the above JSP will do test below.

anyway, here is my original question.
I am trying to create a test case that will definitively show which of the following three approaches a server uses for isThreadSafe=”false”:

*     Keeps a single servlet instance and queues up the requests to it.
*     Makes a pool of instances but lets each instance only handle one request at a time
*     Ignores inThreadSafe altogether.

So, "what do I need to do to distinguish among the three possible cases?") is precisely the point of this assignment.
SingleThreadModel is deprecated and using isThreadSafe="false" is equally bad in real life.

( Note all three approaches have been represented by Tomcat versions in the past.)
The isThreadSafe attribute controls whether the servlet that results from the JSP page will allow concurrent access (the default) or will guarantee that no servlet instance processes more than one request at a time (isThreadSafe=”false”).
Right, here's a class that allows you to read the output of a webserver by setting up sequential connections to it. It shoudl be easy for you to modify it so that it sends multiple "similtaneous" requests to the same page.

package com.bloodredsun;

import java.io.*;
import java.net.*;

public class Test {

      public static void main(String[] args) {
            //set up your urls array
            String[] urls = {"http://localhost:8080/webapp/one.jsp", "http://localhost:8080/webapp/two.jsp" };
            //you don't need this sb but you could something with it if you wanted
            StringBuffer sb = new StringBuffer();
            while(true){//loop forever
                  for( int jj=0 ; jj < urls.length ; jj++){
                        try {
                              //set up HttpURLConnection
                              URL u = new URL( urls[jj] );
                              HttpURLConnection huc = (HttpURLConnection) u.openConnection();
                              huc.setRequestMethod( "GET" );
                              BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));

                              int b = 0;
                              while((b = br.read()) != -1) {
                              // disconnect HttpURLConnection
                              huc.disconnect() ;
                        }catch (IOException e){
                              System.out.println( "Unable to open connection: " + e.getMessage() );
                        }//end try/catch connection
                        try {
                              Thread.sleep( 1000 * 1 ) ;// every 1 second
                        } catch (InterruptedException e) {
                        }//end try/catch Thread.sleep
                  }//end for
            }//end while
      }//end main
}//end class

dkim18Author Commented:
Hm...when I excuted this, it hung. (I inserted same jsp pages in urls array.)
You created array of urls and put thread in sleep, but how does it send multiple simultaneous requests to the same page??

BTW, what possible results can I get? Based on the results, how do I decide which of the following those three approaches a server uses for isThreadSafe=”false”?
It doesn't. You need to do that. It only requires a bit of tuning from you to make the class make simultaneous requests. It would just require you to repeat what I've done in the method and make some more connections for each loop

It doesn't hang. It just doesn't do anything apart from hit the jsps. IF you add

System.out.println("done: " + new Date());

just below

huc.disconnect() ;

you will see that it is making successful connections (don't forget to import java.util.Date at the top).

>>BTW, what possible results can I get?
This is just a way to hit the jsps, not a way of answering your question in a different TA, sorry.

What sort of assignment is this for?

dkim18Author Commented:
thanks for your help. I added some more urls and ran for two mininutes and date and time printed for each second.(a couple of seconds were skipped during excution.) Now, I have to create JSP page that does that and is it possible to create public class in JSP page?

This assignment is for just creating test case that distinguishes among those three possible cases and see what school server does in that case.
Yes it is but the easiest thing to do would be to cut and past the body of the main method into a scriplet in a JSP if that's what you want to do.

I'm sorry I can't do much more than answer your question for you but my hands are tied as regards to doing homework/graded assignments, http://www.experts-exchange.com/help.jsp#hi56, but I'm glad to do that I've helped.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now