[
https://issues.apache.org/jira/browse/LANG-1086?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14336737#comment-14336737
]
Arthur Naseef commented on LANG-1086:
-------------------------------------
Actually, the initial code does block, just like the following blocks and never
terminates:
{code}
while ( true ) {
}
{code}
However, it blocks using a busy-wait, which counters the intent of the class
based on the javadoc comments:
{quote}
but if the object creation in the initialize() method is expensive or if
multiple invocations of initialize() are problematic, it is the better
alternative.
{quote}
To clarify, if the initialize() method is expensive - taking a long time to
execute, the busy-waits consume significant CPU. A test showed all 8 cores of
my system were easily taxed using 9 simultaneous callers to the initializer.
So, in fact, the operation of the method has not changed in regards to
blocking with this change. The method of blocking no longer wastes CPU cycles.
If there is a desire to keep a busy-wait initializer, then perhaps another one
is warranted that uses this "asynchronous" method of blocking. Isn't this the
only initializer that guarantees the initialize() method is only called once
without calling it inside a synchronized block.
> Remove busy wait from AtomicSafeInitializer.get()
> -------------------------------------------------
>
> Key: LANG-1086
> URL: https://issues.apache.org/jira/browse/LANG-1086
> Project: Commons Lang
> Issue Type: Improvement
> Components: lang.concurrent.*
> Reporter: Benedikt Ritter
> Assignee: Benedikt Ritter
> Labels: github
> Fix For: 3.4
>
>
> Placeholder ticket for https://github.com/apache/commons-lang/pull/46
> {quote}
> Remove the busy wait from AtomicSafeInitializer.get().
> Also ensure waiting threads do not wait indefinitely after initialize()
> throws an exception, instead throwing the same exception, re-wrapped, for
> each requester.
> Brought the unit tests up to 100% coverage on AtomicSafeInitializer.
> Eliminated race condition on verifying at least one thread waiting for
> initialize() to complete in another thread.
> {quote}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)