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

x
?
Solved

thread pool of servlet engine

Posted on 2011-10-25
50
Medium Priority
?
351 Views
Last Modified: 2012-06-21
"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   ,
0
Comment
Question by:lovely_rosa
  • 21
  • 18
  • 11
50 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 37023303
Get the source code for the container you're using
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1000 total points
ID: 37023307
This is a huge collection of codes in particuler those related to thread pool:
http://jcip.net/listings.html

Underatdning it may reaquire a lot of time I believ
0
 

Author Comment

by:lovely_rosa
ID: 37023308
how  can I  do that ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 47

Expert Comment

by:for_yan
ID: 37023330
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37023335
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
0
 

Author Comment

by:lovely_rosa
ID: 37023340
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  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37023368
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37023405


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
0
 

Author Comment

by:lovely_rosa
ID: 37027793
if I want to simulate the user behavioral in web application  and create multiple threads that execute the servlets  

how can I achieve that  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37027809
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027810

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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027822

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

0
 

Author Comment

by:lovely_rosa
ID: 37027904
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 :(
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027918
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?
0
 

Author Comment

by:lovely_rosa
ID: 37027932
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 ??  
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027942
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027949
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
0
 

Author Comment

by:lovely_rosa
ID: 37027957
just hot it from inatsnces of your browser   ,   how  can I  do  that  
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027963
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027968
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37027969
It's got to be running in a servlet engine for it to be tested. Use a load testing framework
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37027995
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
0
 

Author Comment

by:lovely_rosa
ID: 37028024
but I dont need load testing  ,  

Again ,  where  is the ThreadFactory  that assign  thread for each request coming from the client  
 to the servlet
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028032
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.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028043
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.
0
 

Author Comment

by:lovely_rosa
ID: 37028049
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 )
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028061
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.

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028084
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37028088
>>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
0
 

Author Comment

by:lovely_rosa
ID: 37028107
I   have  to test other people web Application  , I  just have  to build  the tester  

how  can  I get  the glass fish source code  
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028115
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028131
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028137

with svn cliend you can get to it here:

https://fisheye4.atlassian.com/browse/glassfish-svn
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028141
But no doubt you'll spend a lot of time trying to understand it ; that is not an easy stuff
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028170
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37028265

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
0
 

Author Comment

by:lovely_rosa
ID: 37030200

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

Expert Comment

by:CEHJ
ID: 37030209
>> 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
0
 

Author Comment

by:lovely_rosa
ID: 37030220
okay  can I know  how many threads executing inside  the servlet   and  can I  identify each of them
0
 

Author Comment

by:lovely_rosa
ID: 37030245
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37030248
You can do
out.println(Thread.currentThread().getName());

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37030262
The service method won't return until execution in that method is done
0
 

Author Comment

by:lovely_rosa
ID: 37030310
how  can I know  if there are 2 threads in  servlet the working in parallel
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37030378
The code i gave you will print different names in that case
0
 

Author Comment

by:lovely_rosa
ID: 37030425
I did the following


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

put it does not work
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37030565
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

0
 

Author Comment

by:lovely_rosa
ID: 37030683
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

0
 

Author Comment

by:lovely_rosa
ID: 37031556
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 !!!  


0
 

Author Comment

by:lovely_rosa
ID: 37032369
thanks for ( for_yan  and CEHJ )  
0
 

Author Comment

by:lovely_rosa
ID: 37032454
by the way I did not  get  the  answer but  I  accept your solution as partial solution

thanks  again
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
A solution for Fortify Path Manipulation.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question