Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Trustin Lee
It's better than never. :) On Fri, 16 May 2008 05:44:23 +0900, Pauls, Karl <[EMAIL PROTECTED]> wrote: Sorry for being a little late on this, but for behavior-changing attributes one technique which I have practiced is to make all fields final and when changes are needed I swap out the implem

RE: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Pauls, Karl
Sorry for being a little late on this, but for behavior-changing attributes one technique which I have practiced is to make all fields final and when changes are needed I swap out the implementation since my enclosing system is thread-safe. For example, the filter and protocol chains are thread

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Emmanuel Lecharny
이희승 (Trustin Lee) wrote: On Thu, 15 May 2008 16:47:32 +0900, Emmanuel Lecharny <[EMAIL PROTECTED]> wrote: 이희승 (Trustin Lee) wrote: The problem is we have so many properties which needs visibility independent from each other. Do we have a list of all the properties we need to protect? This

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Trustin Lee
On Thu, 15 May 2008 16:47:32 +0900, Emmanuel Lecharny <[EMAIL PROTECTED]> wrote: 이희승 (Trustin Lee) wrote: The problem is we have so many properties which needs visibility independent from each other. Do we have a list of all the properties we need to protect? This could be a good start t

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Emmanuel Lecharny
이희승 (Trustin Lee) wrote: The problem is we have so many properties which needs visibility independent from each other. Do we have a list of all the properties we need to protect? This could be a good start to discuss about the best mechanism to use to protect them. If we are going to use a loc

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Emmanuel Lecharny
Hi guys, First, I want to appologize for the tone I've used in some of my mails and on IRC. I had a bad day yesturday, and just was too much heated. Sorry for that, Trustin and David. Now that I have had a good night sleep, let's address the problem a little bit more quietly. Dmitry conce

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Trustin Lee
On Thu, 15 May 2008 16:08:58 +0900, Maarten Bosteels <[EMAIL PROTECTED]> wrote: On Thu, May 15, 2008 at 12:40 AM, 이희승 (Trustin Lee) <[EMAIL PROTECTED]> wrote: Yes. I was actually talking about the configuration properties which meets the two criteria. Of course, counters, which were ori

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-15 Thread Maarten Bosteels
On Thu, May 15, 2008 at 12:40 AM, 이희승 (Trustin Lee) <[EMAIL PROTECTED]> wrote: > Yes. I was actually talking about the configuration properties which meets > the two criteria. > > Of course, counters, which were originally mentioned by Dmirty, should use > AtomicIntegers. > > So.. basically we w

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Trustin Lee
Yes. I was actually talking about the configuration properties which meets the two criteria. Of course, counters, which were originally mentioned by Dmirty, should use AtomicIntegers. So.. basically we were mixing up two kinds of properties in our discussion. To sum up: * Use volatil

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
David M. Lloyd wrote: In the case for that field, an AtomicInteger is clearly called for. Absolutely. And the authors mention it. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
Maarten Bosteels wrote: Hello, Brian Goetz [1] writes: "You can use volatile variables instead of locks only under a restricted set of circumstances. Both of the following criteria must be met for volatile variables to provide the desired thread-safety: * Writes to the variable do not depe

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread David M. Lloyd
In the case for that field, an AtomicInteger is clearly called for. - DML On 05/14/2008 01:08 PM, Maarten Bosteels wrote: Hello, Brian Goetz [1] writes: "You can use volatile variables instead of locks only under a restricted set of circumstances. Both of the following criteria must be met fo

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Maarten Bosteels
Hello, Brian Goetz [1] writes: "You can use volatile variables instead of locks only under a restricted set of circumstances. Both of the following criteria must be met for volatile variables to provide the desired thread-safety: * Writes to the variable do not depend on its current value.

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread David M. Lloyd
On 05/14/2008 12:22 PM, Emmanuel Lecharny wrote: David M. Lloyd wrote: On 05/14/2008 11:57 AM, Emmanuel Lecharny wrote: David M. Lloyd wrote: On 05/14/2008 11:20 AM, Emmanuel Lecharny wrote: What I can tell at least though is that the session configuration properties provided by IoService sh

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
David M. Lloyd wrote: On 05/14/2008 12:11 PM, Emmanuel Lecharny wrote: David M. Lloyd wrote: On 05/14/2008 10:55 AM, Emmanuel Lecharny wrote: Sangjin Lee wrote: Hmm... Could you share a simple example of a non-volatile variable that respects the volatile contract? any boolean. This i

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
David M. Lloyd wrote: On 05/14/2008 11:57 AM, Emmanuel Lecharny wrote: David M. Lloyd wrote: On 05/14/2008 11:20 AM, Emmanuel Lecharny wrote: What I can tell at least though is that the session configuration properties provided by IoService should be volatile, because they are accessed in a

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread David M. Lloyd
On 05/14/2008 12:11 PM, Emmanuel Lecharny wrote: David M. Lloyd wrote: On 05/14/2008 10:55 AM, Emmanuel Lecharny wrote: Sangjin Lee wrote: Hmm... Could you share a simple example of a non-volatile variable that respects the volatile contract? any boolean. This is incorrect. Changes m

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Jeroen Brattinga
This page is pretty clear on this subject: http://www.ibm.com/developerworks/java/library/j-praxis/pr50.html In short: "If concurrency is important and you are not updating many variables, consider using volatile. If you are updating many variables, however, using volatile might be slower than usi

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
David M. Lloyd wrote: On 05/14/2008 10:55 AM, Emmanuel Lecharny wrote: Sangjin Lee wrote: Hmm... Could you share a simple example of a non-volatile variable that respects the volatile contract? any boolean. This is incorrect. Changes made to a boolean that is not volatile may never b

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread David M. Lloyd
On 05/14/2008 11:57 AM, Emmanuel Lecharny wrote: David M. Lloyd wrote: On 05/14/2008 11:20 AM, Emmanuel Lecharny wrote: What I can tell at least though is that the session configuration properties provided by IoService should be volatile, because they are accessed in a different thread (I/O p

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
David M. Lloyd wrote: On 05/14/2008 11:20 AM, Emmanuel Lecharny wrote: What I can tell at least though is that the session configuration properties provided by IoService should be volatile, because they are accessed in a different thread (I/O processor) almost always. Use synchronization, not

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread David M. Lloyd
On 05/14/2008 11:20 AM, Emmanuel Lecharny wrote: What I can tell at least though is that the session configuration properties provided by IoService should be volatile, because they are accessed in a different thread (I/O processor) almost always. Use synchronization, not volatile. it's too dang

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread David M. Lloyd
On 05/14/2008 10:55 AM, Emmanuel Lecharny wrote: Sangjin Lee wrote: Hmm... Could you share a simple example of a non-volatile variable that respects the volatile contract? any boolean. This is incorrect. Changes made to a boolean that is not volatile may never become visible in another

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Trustin Lee
On Thu, 15 May 2008 01:20:37 +0900, Emmanuel Lecharny <[EMAIL PROTECTED]> wrote: 이희승 (Trustin Lee) wrote: What I can tell at least though is that the session configuration properties provided by IoService should be volatile, because they are accessed in a different thread (I/O processor) a

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
이희승 (Trustin Lee) wrote: Well, don't we need to think about this issue from the MINA standpoint? I don't see that as an issue, as far as the properties are protexted with correct synchronization. MINA is a framework / library and is considereed to be thread-safe in most cases, especially class

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Trustin Lee
Well, don't we need to think about this issue from the MINA standpoint? There's already plenty resources related with volatile and synchronized keyword in the world. MINA is a framework / library and is considereed to be thread-safe in most cases, especially classes related with IoSession

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
Sangjin Lee wrote: Hmm... Could you share a simple example of a non-volatile variable that respects the volatile contract? any boolean. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Sangjin Lee
Hmm... Could you share a simple example of a non-volatile variable that respects the volatile contract? Thanks, Sangjin On Wed, May 14, 2008 at 8:38 AM, Emmanuel Lecharny <[EMAIL PROTECTED]> wrote: > Sangjin Lee wrote: > >> If it wasn't obvious (I guess it was not), what I meant was "using >> n

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
Sangjin Lee wrote: If it wasn't obvious (I guess it was not), what I meant was "using non-volatile variables *in the absence of any synchronization* ...". :) Even then, this is not dangerous, as far as you respect the Volatile contract. Synchronization is not needed in this case. -- -- cord

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Maarten Bosteels
I agree with Emmanuel: volatile might be good enough if you *only* care about *visibility* but a synchronized block makes the intention of the code more clear. Are the performance benefits of volatile substantial ? I would guess not. Maarten On Wed, May 14, 2008 at 5:17 PM, Emmanuel Lecharny <[

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Sangjin Lee
If it wasn't obvious (I guess it was not), what I meant was "using non-volatile variables *in the absence of any synchronization* ...". :) Regards, Sangjin On Wed, May 14, 2008 at 8:17 AM, Emmanuel Lecharny <[EMAIL PROTECTED]> wrote: > Sangjin Lee wrote: > >> IMHO using non-volatile variables in

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Sangjin Lee
On Wed, May 14, 2008 at 7:59 AM, Jeroen Brattinga < [EMAIL PROTECTED]> wrote: > Volatile means that a thread won't cache the (value of) a variable. So > your making sure that every thread sees updates on that variable. > > The Volatile keyword DOES NOT provide protection against multiple > read/wr

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
Sangjin Lee wrote: IMHO using non-volatile variables in a multi-threaded situation is living dangerously. I don't see how it can be dangerous, as far as you synchronized the code correctly. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Emmanuel Lecharny
Jeroen Brattinga wrote: Volatile means that a thread won't cache the (value of) a variable. So your making sure that every thread sees updates on that variable. More precisely, defining a variable as 'volatile' will forbid the JiT compiler to optimize the code up to a point the variable is p

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Jeroen Brattinga
Volatile means that a thread won't cache the (value of) a variable. So your making sure that every thread sees updates on that variable. The Volatile keyword DOES NOT provide protection against multiple read/writes from different threads! Synchronization, locks or atomic variables are still neede

Re: Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-14 Thread Sangjin Lee
AFAIK, volatile is the most efficient way of doing memory barriers for variables that are accessed for read and write by multiple threads. Synchronizations or atomic variables are alternatives, but possibly more expensive. Also, I believe doing memory barriers is essential for visibility... IMHO

Should all configuration properties be volatile? (Was: Re: Visibility of idle time changes in BaseIoSession)

2008-05-13 Thread Trustin Lee
Dmirty raised an interesting question in our configuration properties. We have so many configuration properties - should each propery declared as volatile? Would there be more efficient way than doing so? On Thu, 08 May 2008 16:43:51 +0900, Дмитрий Батрак <[EMAIL PROTECTED]> wrote: As ment