On Wed, 19 Sep 2001, Graham, Billy wrote:

> Hi Milt,
>
> While away on my coffee break I sat and stirred (OK bad pun) and was
> thinking along the same lines as you just suggested.
> I have already moved the synchronized scope to just the block of code which
> I know was being affected (? now at hack-saw level) within the method and
> everything is still OK. I am not using multiple threads and, as I am still
> developing the servlet, there was only me making a single request to the
> servlet,  so I still do not know why this problem was originally happening.
> Any further ideas would be welcomed.

Well, that's improvement :-).  Still, it would be best if you were
able to determine exactly what is going on, where the threading issue
is.  I believe there are cases where multiple threads can come up even
if you have just one request -- didn't you say there was evidence of
two calls to the method? -- and at some point you are probably going
to have the method be running in a multi-request/multi-threaded
environment, so you will need to deal with it at some point.

If you have it isolated to a relatively small block, you might post
the code to the list to see what people here may notice.  Make sure
it's clear where variables are declared, because that's a factor in
whether code is thread-safe.


> Well, when you get back from your coffee break, I suggest you start
> taking a closer look at your code and try to find a better solution,
> because this isn't really a good one.  If using synchronized on the
> method solved your problem, then it is a threading-related issue.  But
> synchronizing the entire method is like using a chain-saw when a
> scalpel is what's really needed.  Basically, it could cause a
> significant performance degradation.  You need to find more
> specifically where the threading issue is, and reduce it as much as
> possible; eliminating it would be best, but if you can't, make it as
> small as possible and put a synchronized around just that block.  I
> haven't been following this thread that closely, so I don't have
> particular suggestions, but it seems some people suggesting checking
> whether you're using instance variables or not.
>
> FWIW, protected shouldn't have anything to do with this, it just
> controls what subclasses/packages have access to the method.  I
> suspect all your code is in the one class, and you won't be
> subclassing it, so it's not really going to affect anything (probably
> you should remove it).
>

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
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