@@ -216,7 +216,7 @@ void rollback() throws SailException {
216216 if (tripleStoreException != null ) {
217217 throw wrapTripleStoreException ();
218218 } else {
219- Thread .yield ();
219+ Thread .onSpinWait ();
220220 }
221221 }
222222 } else {
@@ -478,7 +478,7 @@ public void flush() throws SailException {
478478 if (tripleStoreException != null ) {
479479 throw wrapTripleStoreException ();
480480 } else {
481- Thread .yield ();
481+ Thread .onSpinWait ();
482482 }
483483 }
484484 }
@@ -491,7 +491,7 @@ public void flush() throws SailException {
491491 if (tripleStoreException != null ) {
492492 throw wrapTripleStoreException ();
493493 } else {
494- Thread .yield ();
494+ Thread .onSpinWait ();
495495 }
496496 }
497497 }
@@ -676,30 +676,29 @@ private void startTransaction(boolean preferThreading) throws SailException {
676676 } else if (Thread .interrupted ()) {
677677 throw new InterruptedException ();
678678 } else {
679- Thread .yield ();
679+ Thread .onSpinWait ();
680680 }
681681 }
682682 }
683683
684- // keep thread running for at least 2ms to lock-free wait for the next
684+ // keep thread running for a short while to lock-free wait for the next
685685 // transaction
686686 long start = 0 ;
687687 while (running .get () && !nextTransactionAsync ) {
688688 if (start == 0 ) {
689- // System.currentTimeMillis() is expensive, so only call it when we
690- // are sure we need to wait
691- start = System .currentTimeMillis ();
689+ // only call System.nanoTime() if we need to wait
690+ start = System .nanoTime ();
692691 }
693692
694- if (System .currentTimeMillis () - start > 2 ) {
693+ if (System .nanoTime () - start > 100000 ) {
695694 synchronized (storeTxnStarted ) {
696695 if (!nextTransactionAsync ) {
697696 running .set (false );
698697 return ;
699698 }
700699 }
701700 } else {
702- Thread .yield ();
701+ Thread .onSpinWait ();
703702 }
704703 }
705704 }
@@ -846,15 +845,15 @@ public void execute() throws Exception {
846845 if (tripleStoreException != null ) {
847846 throw wrapTripleStoreException ();
848847 } else {
849- Thread .yield ();
848+ Thread .onSpinWait ();
850849 }
851850 }
852851
853852 while (!removeOp .finished ) {
854853 if (tripleStoreException != null ) {
855854 throw wrapTripleStoreException ();
856855 } else {
857- Thread .yield ();
856+ Thread .onSpinWait ();
858857 }
859858 }
860859 return removeCount [0 ];
@@ -932,7 +931,7 @@ public CloseableIteration<? extends Statement> getStatements(Resource subj, IRI
932931 try {
933932 logger .warn ("Failed to get statements, retrying" , e );
934933 // try once more before giving up
935- Thread .yield ();
934+ Thread .onSpinWait ();
936935 return createStatementIterator (txn , subj , pred , obj , explicit , contexts );
937936 } catch (IOException e2 ) {
938937 throw new SailException ("Unable to get statements" , e );
0 commit comments