aspose file tools*
The moose likes Servlets and the fly likes Concurrency  Issue in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Concurrency  Issue in Servlet " Watch "Concurrency  Issue in Servlet " New topic
Author

Concurrency Issue in Servlet

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1382
How concurrency issues are solved in Servlet ?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I think you will have to tell us a bit more about what you want to know.

The servlet API is by its nature concurrent. The service(..) and doXX(..) methods of a servlet (and thus any methods they call) can and will be executed by many threads at once, under the control of the servlet container.

Are you asking how to ensure that any servlet code you write is "thread safe" (also known as "reentrant") ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Dillip Mohapatra
Greenhorn

Joined: Jul 07, 2004
Posts: 7
Hi Kri,

I think, you must localize all your objects and instances that will solve the concurrency problem. For instance, define a separate class, containing all the objects you are using inside the servlet. Now instantiate it inside the servlet and access them through this instance. This should solve your concurrency problem, that normally we face.

Thanks and Regards
Dillip


Dillip Mohapatra
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
I first time read a solution like that Dilip. Is this widely used in the industry? I doubt this.

Anyone knows?

Regards,
Leena


[SCJP2, SCWCD1.3, SCBCD]
M. Gagnon
Ranch Hand

Joined: Feb 18, 2004
Posts: 68
Dillip,

What is the advantage of using an inner class defined in a servlet over instantiating some class defined in a separate file and "adding it" by using the setAttribute() method of ServletContext, ServletRequest or HttpSession objects?
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
its up to the programmer to solve it.To avoid this you may want to implement the SingleThreadModel interface in your servlet. There is good article on that here.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
Leena said:
I first time read a solution like that Dilip. Is this widely used in the industry? I doubt this.

Creating a class to hold user specific data is done all the time. For one thing, it makes things simpler than plugging various bits into the session and hauling them back out again. Note that we are NOT talking about putting everything you use in this class, just the user specific data. If you are using JSP, this class is an obvious candidate for the JavaBean interface.

Another (frequently un-appreciated) reason to create such a user-specific class is the ease of debugging. You can test it outside the servlet environment - a vast simplification.

Bill
(Avoid the SingleThreadModel like the plague - if you think you need it, your architecture is wrong.)
[ July 12, 2004: Message edited by: William Brogden ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Concurrency Issue in Servlet