commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Arthur Naseef (JIRA)" <>
Subject [jira] [Commented] (LANG-1086) Remove busy wait from AtomicSafeInitializer.get()
Date Wed, 25 Feb 2015 16:47:05 GMT


Arthur Naseef commented on LANG-1086:

Actually, the initial code does block, just like the following blocks and never terminates:

while ( true ) {

However, it blocks using a busy-wait, which counters the intent of the class based on the
javadoc comments: 

but if the object creation in the initialize() method is expensive or if multiple invocations
of initialize() are problematic, it is the better alternative.

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:
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.concurrent.*
>            Reporter: Benedikt Ritter
>            Assignee: Benedikt Ritter
>              Labels: github
>             Fix For: 3.4
> Placeholder ticket for
> {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
> {quote}

This message was sent by Atlassian JIRA

View raw message