Re: ThreadPoolExecutor backport
- From: Lew <lew@xxxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 12:32:56 -0700 (PDT)
Robert Klemme wrote:
I faintly remember articles
about the flaws of the Java memory model before Java 5 and I believe
volatile handling was one of them. Or am I mixing up something?
What you are remembering is that 'volatile' prior to Java 5 only
guaranteed visibility of changes through the volatile variable
itself. Other changes might not have propagated.
So given
class Foo
{
volatile int flag;
int value; // not volatile
...
}
the old memory model would guarantee visbility of changes to 'flag',
but not other changes. Code like:
value += 17;
flag = 1;
in one thread guaranteed that another thread would see 'flag' as 1,
but not that it would see the change in 'value'. In the new memory
model, the change to 'value' /happens-before/ the change to 'flag', so
it is visible across threads.
--
Lew
.
- References:
- ThreadPoolExecutor backport
- From: Philipp
- Re: ThreadPoolExecutor backport
- From: Lew
- Re: ThreadPoolExecutor backport
- From: Robert Klemme
- Re: ThreadPoolExecutor backport
- From: Lew
- Re: ThreadPoolExecutor backport
- From: Robert Klemme
- ThreadPoolExecutor backport
- Prev by Date: Re: ThreadPoolExecutor backport
- Previous by thread: Re: ThreadPoolExecutor backport
- Next by thread: bounds of line2d
- Index(es):
Relevant Pages
|