[
https://issues.apache.org/jira/browse/SOLR-11782?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16300675#comment-16300675
]
Dawid Weiss commented on SOLR-11782:
------------------------------------
[~dsmiley] Condition has a fine-grained awaitNanos (and arbitrary time unit
await, converted to nanos). If you glimpse at the openjdk code implementation
of these you'll see what I mean by fine-grained (lock parking, etc.). The
method accepting {{Date}} is indeed using currentTimeMillis but this isn't what
I was referring to.
I personally like the latest patch more (thanks [~tomasflobbe]!), but I'll
leave it for you guys to decide. One nitpick --
{code}
long timeoutNanos = TimeUnit.MILLISECONDS.toNanos(timeoutMs);
{code}
you could simply use await(millis, TimeUnit.MILLIS); the conversion to nanos is
then internally done anyway.
> LatchWatcher.await doesn’t protect against spurious wakeup
> ----------------------------------------------------------
>
> Key: SOLR-11782
> URL: https://issues.apache.org/jira/browse/SOLR-11782
> Project: Solr
> Issue Type: Bug
> Security Level: Public(Default Security Level. Issues are Public)
> Reporter: Tomás Fernández Löbbe
> Priority: Minor
> Attachments: SOLR-11782.patch, SOLR-11782.patch, SOLR-11782.patch
>
>
> I noticed that {{LatchWatcher.await}} does:
> {code}
> public void await(long timeout) throws InterruptedException {
> synchronized (lock) {
> if (this.event != null) return;
> lock.wait(timeout);
> }
> }
> {code}
> while the recommendation of lock.wait is to check the wait condition even
> after the method returns in case of spurious wakeup. {{lock}} is a private
> local field to which {{notifyAll}} is called only after a zk event is being
> handled. I think we should check the {{await}} method to something like:
> {code}
> public void await(long timeout) throws InterruptedException {
> assert timeout > 0;
> long timeoutTime = System.currentTimeMillis() + timeout;
> synchronized (lock) {
> while (this.event == null) {
> long nextTimeout = timeoutTime - System.currentTimeMillis();
> if (nextTimeout <= 0) {
> return;
> }
> lock.wait(nextTimeout);
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]