Mostly true.

You really only need to synchronize the specific block of code which is
non-thread safe.  This may or may not be the entire method.  If the method
is something like doGet(), then synchronizing the whole thing would almost
always be a bad idea.

Basically, you want to minimize the amount of time that you spend in a
synchronized block because other requests will block waiting for each one to
finish serrially.

If you have a copy of Jason Hunter's book JAVA Servlet Programming, it is
clearly explained in Chapter 3.

Steven

> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's
> Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On
> Behalf Of Marc
> Krisjanous
> Sent: Sunday, May 21, 2000 5:11 PM
> To: [EMAIL PROTECTED]
> Subject: synchronized methods - simple question
>
>
> Hi all,
> I wonder if anyone can confirm the following:
>
> I have a servlet that will call a synchronized method that
> will write to a
> file.  My understanding of how Servlets work is that for
> every web session
> (web browser) which calls the servlet the servlet will have a
> thread created
> for that session in which data will be stored for that
> session but each
> thread will use the same method(e.g the class and methods will not be
> created for each thread).  Thus in order to access and write
> to external
> media you need to make that method synchronized since in
> theory there is
> only one method that all threads share.
>
> Is this true??
>
> Best Regards
>
> Marc
>
> -----Original Message-----
> From: Shawn McKisson [mailto:[EMAIL PROTECTED]]
> Sent: Monday, 22 May 2000 2:04 AM
> To: [EMAIL PROTECTED]
> Subject: Re: how to start execute a servlet in own computer not in
> internet
>
>
> You don't need a network connection to use localhost. That name should
> resolve locally to 127.0.0.1.
> If it doesn't, you should add a static route so that it does.
>
> --shawn
>
> ----- Original Message -----
> From: Camille Bell <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, May 19, 2000 12:39 PM
> Subject: Re: how to start execute a servlet in own computer
> not in internet
>
>
> > Kerem,
> >
> > The simple answer to your question is that you can't run a
> servlet engine
> > without some sort of network connection. It doesn't have to be the
> > internet, it could be a local area net. In fact it could be
> a network of a
> > single machine (not too useful, but it is configurable).
> The point is you
> > MUST have an IP address.
> >
> > You have a few of choices of how to get an IP address.
> >
> >       ---- Choice 1 -----
> >
> > Since you receive this list mail, you must have some sort of active
> network
> > connection to send us email. If this is also your Servlet
> machine, it will
> > be easy.  Let's assume that you got here through an ISP
> using a dial up.
> If
> > so great, that's all you need. Here's the order of things
> you should do.
> >
> >   1. Connect to the internet as usual. Since your coming in
> through a dial
> > up, you ISP assigns to an ISP address once you are
> connected. That's what
> > your server engine needs. Wait until your ISP confirms your
> login before
> > the next step.
> >
> >   2. Start your servlet engine. Wait until it is all the
> way up before the
> > next step.
> >
> >   3. Get into your browser and use "localhost" as the host name.
> >
> >
> > If you used DSL, Cable, Satellite etc. you'd already be set
> up with a
> > permanent IP address and you wouldn't be having this
> problem, so we can
> > skip that possibility.
> >
> >       ---- Choice 2 -----
> >
> >   1. If your system is part of an active local area
> network, you also have
> > an IP address. Assuming that you are a client in a client/server
> > configuration, just make sure you are connected to the server.
> >
> >   2. Start your servlet engine. Wait until it is all the
> way up before the
> > next step.
> >
> >   3. Get into your browser and use "localhost" as the host name.
> >
> >
> >       ---- Choice 3 -----
> >
> > If for some reason you have a completely standalone system
> then you need
> to
> > make the system think it's a network.
> >
> >   1. Get into the network setup tool of whatever operating
> system you have
> > and give yourself a permanent IP address. You'll have to
> make sure you
> have
> > the TCP/IP protocol first.
> >
> > In Windows NT you do this by getting into the Control Panel
> and double
> > clicking the Network icon. Then you click on the Protocol
> tab and click on
> > TCP/IP line. Finally you click the 2nd Radio Button (Specify and IP
> > address) and type in an address. Click Apply and OK. You
> might need to
> > reboot before its effective. I'm not sure.
> >
> > If you are standalone, it doesn't matter what number you
> give yourself. If
> > you latter connect to the internet or other computers then
> you'll need to
> > undo that, but for the moment you will be safe.
> >
> >   2. Start your servlet engine. Wait until it is all the
> way up before the
> > next step.
> >
> >   3. Get into your browser and use "localhost" as the host name.
> >
> >
> > One of these approaches should get you further than you are now.
> >
> >
> > Camille
> >
> >
> ______________________________________________________________
> _____________
> > To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the
> body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives:
> http://archives.java.sun.com/archives/servlet-interest.html
> > Resources:
> http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
> http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
> http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to