I believe Alan Holub did some tests and found out that achieving a lock when
one was already held was no faster then achieving the lock the first time,
which would mean that your code would actually be slower.
    (*Chris*)

----- Original Message -----
From: Alex Smith <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 16, 1999 2:56 PM
Subject: Re: (SUGGESTION) OutOfMemoryException


> This is grossly off topic -- I hope this message is the last in the
thread.
> Take this to private email, an appropriate forum on JDC or the Usenet
> newsgroup(s).
>
> You can (and should) go one step further when working with StringBuffer,
> namely synchronize on an instance when calling append(), like so:
>
> StringBuffer sb = new StringBuffer();
> synchronized (sb) {
>
> sb.append("foo");
> sb.append("bar");
> sb.append("baz");
>
> }
>
> The append() methods of StringBuffer are synchronized in both 1.1
> and 1.2, at least the ones actually doing any work. (Some simply convert
the
> argument to String and call an appropriate append()). There is an overhead
> involved in grabbing and releasing the lock, so it is inefficient to free
a
> lock, just to grab it again a few lines of code later. Therefore, if
you're
> doing more than one append(), it is better to synchronize on an instance,
> thereby freeing the JVM from the responsibility of re-acquiring the lock
for
> every append() call.
>
> Note: beware of JDK 1.2 API docs on Sun's website. It looks like
> 1.2 javadoc omits (by design or explicit command-line arguments)
> two out of three 'non-significant' (not used while computing a signature
of
> a method) modifiers, namely keywords "synchronized" and "native".
Therefore,
> you may be led to believe that 1.2 append() is not synchronized. This is
not
> true. Always read the source and trust noone :P
>
> Alex.
>
>
> _______________________________________________________________
> Get Free Email and Do More On The Web. Visit http://www.msn.com
>
>
___________________________________________________________________________
> 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