Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Can we write synchronize service method in servlet?If no why

Thread view: 
Mahesh - 12 May 2006 11:53 GMT
Hi Guys
I am new to this group . I working on J2ME and learning Servlet .
I have question on synchronization of servlet.If not whay we cannot
write .
hiwa - 12 May 2006 11:59 GMT
You mean, synchronize on what???
Mahesh - 12 May 2006 12:31 GMT
service method i.e
public synchronize void service (HttpServletRequest
req,HttpServletResponse res)
chris brat - 12 May 2006 13:03 GMT
I dont think that adding the synchronized keyword will cause you a
problem with either compilation or running - it didn't in the simple
example class I wrote.

But why would you want to do this?  it would kill performance.

The functionality seems to describe the behaviour of the
SingleThreadModel which was deprecated.
Juha Laiho - 16 May 2006 21:13 GMT
"chris brat" <chrisBrat@gmail.com> said:
>I dont think that adding the synchronized keyword will cause you a
>problem with either compilation or running - it didn't in the simple
[quoted text clipped - 4 lines]
>The functionality seems to describe the behaviour of the
>SingleThreadModel which was deprecated.

SingleThreadModel is quite a different beast than synchronized service
method. Ok, both guarantee, that there is just one thread running
in the service method of a single servlet instance.

Then to the difference: if you use SingleThreadModel, the servlet container
will be allowed to create multiple instances of your servlet class
to allow concurrent processing of multiple requests (which would be
a big no-no, if you chose the SingleThreadModel to protect some fragile
constructs you access from within the service method). If, on the other
hand, you synchronize the service method (and do not use the
SingleThreadModel), the container will be limited to just one instance
of any given servlet - thus permitting just one request running in
the service method of the servlet. However, this would be a major
performance bottleneck; it'd be better to use some more fine-grained
locking.
Signature

Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
        PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)

Thomas Fritsch - 12 May 2006 13:08 GMT
> Hi Guys
> I am new to this group . I working on J2ME and learning Servlet .
> I have question on synchronization of servlet.If not whay we cannot
> write .

I am not sure about what you mean with "synchronization of servlet". May
be you mean the SingleThreadModel as specified in
<http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/SingleThreadModel.html>.
You can use it like this:
public class MyServlet extends HttpServlet implements SingleThreadModel {
 ...
}

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.