I would agree with Joel's assesment that aquireing a monitor (an expensive
operation onto it's self) global object will creates a bottle neck.  I'm not
sure
that I understand his assertion that setting a the head of the (circular)
queue
is an atomic operation.  I believe that would depend on the implementation.
You might consider having a number of queues where each thread might be
assigned to one.  This should reduce lock contention.  If the reader doesn't
have to accuire the monitor, then things are even better.

Kirk
-----Original Message-----
From: Sanjay Nambiar <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Wednesday, November 24, 1999 11:58 PM
Subject: Re: Java implementation Query:Urgent


>Hi Joel,
>I have tried to use a queue and implement a solution where Clients threads
>that write to the queue use inter thread communication to notify a thread
>which would then pick up the data and write to a file.
>Here the getting from the queue and putting to the file methods are
>synchronized.
>The log class(helper class) is implemented as a Singleton.
>However I still lose messages along the way when the number of hits to
>writing to the queue increase in comparison to
>writing to the File.
>Joel I have not clearly understood your solution.
>Could you elaborate with my example in mind.
>Regards,
>SANJAY
>
>> -----Original Message-----
>> From: Joel Crisp [SMTP:[EMAIL PROTECTED]]
>> Sent: Wednesday, November 24, 1999 4:50 PM
>> To:   [EMAIL PROTECTED]
>> Subject:      Re: Java implementation Query:Urgent
>>
>> Hi Peter
>>
>> I can't give you code samples - I'm a consultant so I'd have to
>> ask you to pay ;-(
>>
>> I can go into a bit more detail:
>>
>> The main issue is the impact on performance of forcing all threads
>> to synchronize on one global object. If you have a per-thread
>> circular log queue, each thread can post log messages to the front of the
>> queue without synchronizing, as the operation of bumping the queue
pointer
>> is atomic (this is a well known feature of circular queues dating back
>> to the old days of assembler). A global log manager thread can then spin
>> round the queues, pulling off log objects and printing them. This ensures
>> that all writes to the log file are serialized appropriately. Even if you
>> want to do a bit more work and need to synchronize, you are only blocking
>> the local thread (on its queue), and the log thread - not the other
>> worker threads so you are not going to impact performace.
>>
>> Hope this clarifies the situation.
>>
>> Joel
>>
>> Peter Michael wrote:
>> >
>> > > Hi
>> > >
>> > > Both of these solutions are BAD !
>> > >
>> > > You should implement a queue which can take multiple threads
>> > > writing log objects
>> > > to the queue. You can do this without synchronization using
>> > > the atomic features
>> > > of the java language calculations and volatile variables.
>> >
>> > Could you please give a code example?
>> >
>> > > Then use one thread
>> > > to pull the log objects of the queue and write them to the file.
>> > >
>> > > Locking on a shared object will bottleneck your performance,
>> > > and JNI is discouraged
>> > > in EJBs.
>> > >
>> > > Joel Crisp, Senior Java Architect, SUN PS Java Center (UK)
>> > >
>> > > Srinivasan VS wrote:
>> > > >
>> >
>> >
>>
==========================================================================
>> =
>> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
>> body
>> > of the message "signoff EJB-INTEREST".  For general help, send email to
>> > [EMAIL PROTECTED] and include in the body of the message "help".
>>
>>
==========================================================================
>> =
>> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
>> body
>> of the message "signoff EJB-INTEREST".  For general help, send email to
>> [EMAIL PROTECTED] and include in the body of the message "help".
>
>===========================================================================
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff EJB-INTEREST".  For general help, send email to
>[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to