Link to home
Start Free TrialLog in
Avatar of lovely_rosa
lovely_rosa

asked on

thread pool of servlet engine

"At startup, the servlet engine creates a thread pool with number of threads in a pool equal to the minimum number of threads configured."

the question is  :
how  can I get into the thread pool  I want  to see the source code of thread pool  how they program it   ,
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lovely_rosa
lovely_rosa

ASKER

how  can I  do that ?
Look at that link , which I posted above - there is a whole section - applying thread pools.

Perhpas it is not necerrsray about servlets but will give you some impression.

It is probably not a simple stuff, though.
http://apache.mirror.rbftpnetworks.com/tomcat/tomcat-7/v7.0.22/src/apache-tomcat-7.0.22-src.zip

although i'm 99% certain, given your previous question, that you'll be wasting your time
thanks for   you  (  for_yan  , and    CEHJ )  I am  going to study the links you gave me and then I will come with my questions  
Certainly studying a general thread pool will be of no help whatsoever if you need to know how the thread pool of your web container works


look at this faq (I also posted it in your other question, as it seesm relevant for both questions)
http://www.codestyle.org/java/servlets/faq-Threads.shtml#singlethreadedmodel
if I want to simulate the user behavioral in web application  and create multiple threads that execute the servlets  

how can I achieve that  
That will happen in the normal course of running it. The more simultaneous requests for the servlet you get, the more threads will be created to service them

You can read here about load testing tools:
http://en.wikipedia.org/wiki/Load_testing

I believe JMeter is the most popular in Java world

this is JMeter site:
http://jakarta.apache.org/jmeter/

I would also suggest first to try normal course of running it
Do you expect really huge numbers of hits on your page?
It really odes not happen immediately, unless you are replacing software under already known site

can I call servlet from threads  , I would  like  to create 2 threads the 2 threads call the servlet   ?  is it possible

I mean  can I create class that generate threads and the generated thread go to the servlet ?

how can I do that  ,  my head will be exploded every where in my room :(
What you mean by calling the servlet? You can access the sevlet page form your other java application.
why would it matter if you access it from 2 different threads or two different instances of application?
okay  ,  I want  to test the web Application before upload it to the server , so I have to simulate user behavioral  ,  by creating multiple threads that call the service method in the servlet

how  can I do  that ??  
No you need to have test web serevr and access your web application as users would be accessing it and you don't need threads for that - just hot it from inatsnces of your browser
But how can you test your web application wwityhout loading ity into your web framework?
Even if you invent soem way - that would be different considtions
just hot it from inatsnces of your browser   ,   how  can I  do  that  
You can teest some speciific methods separately but te whole application - it needs to be loaded as web application and accessed by cleient throhgh the browser or you cna wrote clinet in java and access it; still apllication itself should be deployed in the server in web environemnt
you open your browser once and point to address of your starting page
then open andother browser window andpoint to the same page, and so on.

If you rneed to test when not two or three but many hitting then you need those load testers
It's got to be running in a servlet engine for it to be tested. Use a load testing framework
However before you get involved with load testing make sure you deploy it in web server/servlet engine and ttry it with jaust one or two
clients form browsers - this in itself will ibnitially be a challenge; then when you see it works - you can move on to load testers.

How many clients will be htting your page a day?

Graet majority of all web applications really don't need anny load testers because capacity of the engine is far bneyond thier traffic requirements
but I dont need load testing  ,  

Again ,  where  is the ThreadFactory  that assign  thread for each request coming from the client  
 to the servlet
Why are you concerned with those details?
Go ahead , create you web aplication, deploy it and try to access it first with one browser client then more
It may very well happen that you don't need evebn bother about the threads etc., believe me.
Servlet engine and servlet API are designed to work with many clients.
Unless you do something special in your application they will take care
of all issues of simultaneous access, etc. Worry about it when the problems really show up.
the way I  use  to test  the web application  force me  to  go into the details of  threadfactory  ,   so  that's why  I need help  in this issue   (  I use  temporal  logic   to test web application )
Do you have the web application already working?

As you are asking how to test web application without the web, that causes me to think that you don't have web application itslef as yet.

If you don't have the web application as yet, I'd suggest that you make sure you have access to the servlet engine, web server, etc,
fthen write applicatiion and deploy it, and make it work.
I'm sure after that you'll see you questions about threads etc in quite  new light.
>>Again ,  where  is the ThreadFactory  that assign  thread for each request coming from the client  to the servlet

I've already answered that question: you need to look at the container source code
I   have  to test other people web Application  , I  just have  to build  the tester  

how  can  I get  the glass fish source code  

with svn cliend you can get to it here:

https://fisheye4.atlassian.com/browse/glassfish-svn
But no doubt you'll spend a lot of time trying to understand it ; that is not an easy stuff
If you are specialiszng in testing other peoples web apps, I'd think that it would be a good idea to look at soem existing load testers, like JMeter
and others mentioned above.
I'm working with Java for many years - I hardly rememember the case when I could
get useful information about the applcation fo the glassfish scale  directly from the source code

You actually don't even need the svn client to see the source code of glassfish onthe page above;
This is an example of the code of one of the classes, they can be accessed directly:
https://fisheye4.atlassian.com/browse/glassfish-svn/trunk/v3/connectors/admin/src/main/java/org/glassfish/connectors/admin/cli/ConnectorSecurityMap.java?r=40183

how  can I know  inside the servlet if this  is a thread and if it start execution or not
>> if this  is a thread and if it start execution or not

What do you mean by that? If the servlet's service method has been called, then of course there will be a thread - or it couldn't be called
okay  can I know  how many threads executing inside  the servlet   and  can I  identify each of them
yes  that's true  I can know the starting of the thread  in service method but how  can  I  know  if  the thread finish executing
You can do
out.println(Thread.currentThread().getName());

Open in new window

The service method won't return until execution in that method is done
how  can I know  if there are 2 threads in  servlet the working in parallel
The code i gave you will print different names in that case
I did the following


  Thread.currentThread().setName(name[counter]);
        counter++;
if (Thread.currentThread().getName()=="lovely_rosa")
{
  out.println("hithere");
}

put it does not work
a. you can't really set (or depend upon setting) the names of thread you don't control
b. you can't compare String like that. It has to be


if ("lovely_rosa".equals(Thread.currentThread().getName())

Open in new window

I gave  each request (thread)  a name ,  I want  to say  that  while lovely thread is Alive ()

don't start CEHJ thread

how  can I  achieve that
String name []={"lovely","CEHJ "}; // global variables
public int counter=0; // global variables 
   public boolean flag ; //  global variables 

 protected void doPost(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

  Thread.currentThread().setName(name[counter]);
        counter++;
 PrintWriter out = response.getWriter(  );

out.println(Thread.currentThread());
if (counter==3)
{
    counter=0;
}

if (Thread.currentThread().getName().equals("lovely"))
{
           flag=  Thread.currentThread().isAlive();


}

// rest of the code 
}

Open in new window

out.println(Thread.currentThread().getName());
out.println(Thread.currentThread().getId());

when  I write  this  code inside  the servlet  every time I call the servlet  it gives me the same name

and the same id for the thread it never change !!

again :::  how  can I  identify each thread and know if the thread still working or terminate , and I want to know if 2 threads working at the same time or not   ,  how how how !!!  


thanks for ( for_yan  and CEHJ )  
by the way I did not  get  the  answer but  I  accept your solution as partial solution

thanks  again