Ramesh Venkatraman wrote:

> Hi Folks,
>
>  I have a query here,
>
>   Assuming we have a servlet which incorporates multi-threading (i.e it does
> not use any thread synchronization) and now assuming there is a call to the
> method "log()" somewhere in the servlet. Will this simple method log()
> actually make the servlet to run in a synchronised way?
>   The reason being.
>
> a) The log() method writes the String into a text file. A text file, me
> thinks,  unlike an RDBMS table can be written in a sycnhronized manner and
> not concurrently. (I am using Jrun on IIS.)
>
> b) Or will the servlet engine queue the messages to be written one by one.
>
> c) Will the effect be the same for System.out.println() and
> System.err.println().
>
> Am I missing something very simple here :-).
>

In principle, at least three factors in the implementation affect how much
overhead there is:

* Does the log() implementation write directly to an underlying file,
  or does it just queue messages to an in-memory buffer that is
  flushed asynchronously by a background thread?.

* Does the underlying log stream buffer its output?  If so, you would
  only run into contention at log flush times, not during buffering.

* Does the OS deal efficiently with multithreaded access to a single
  underlying file?  Unix-based systems are, in general, very good at
  this, even across multiple processes.

In practice, you have to be logging an awful lot of stuff before synchronization
on the log would have any appreciable impact.  I would not worry too much about
this issue (unless, of course, you run a profiler on your servlet engine and
find out that it really is an issue :-).

Similar issues apply to System.out, which is usually buffered by the JVM.
System.err is usually unbuffered, because you normally want your error messages
visible as quickly as possible.

>
> Thanx in advance for any answers
>

No problem.

Craig McClanahan


>
> Cheers
> Ramesh
>
> ___________________________________________________________________________
> 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