You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/12/03 23:31:24 UTC
svn commit: r1416706 -
/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPTopGoalIterator.java
Author: andy
Date: Mon Dec 3 22:31:22 2012
New Revision: 1416706
URL: http://svn.apache.org/viewvc?rev=1416706&view=rev
Log:
Remove deadlock situation by reversing lock nesting.
Modified:
jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPTopGoalIterator.java
Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPTopGoalIterator.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPTopGoalIterator.java?rev=1416706&r1=1416705&r2=1416706&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPTopGoalIterator.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/impl/LPTopGoalIterator.java Mon Dec 3 22:31:22 2012
@@ -73,6 +73,14 @@ public class LPTopGoalIterator implement
engine.setTopInterpreter(this);
}
+ /* A Note on lock ordering:
+ *
+ * Elsewhere code takes an LPBRuleEngine then an LPTopGoalIterator
+ * Ensure we do that lock order here as well as just synchronized
+ * on the method reverses the lock ordering, leading to deadlock.
+ */
+
+
/**
* Find the next result in the goal state and put it in the
* lookahead buffer.
@@ -85,9 +93,6 @@ public class LPTopGoalIterator implement
lpEngine = interpreter.getEngine();
}
synchronized (lpEngine) {
- // Elsewhere code takes an LPBRuleEngine then an LPTopGoalIterator
- // Ensure we do that lock order here as well as just synchronized
- // on the method reverses the locks takne, leading to deadlock.
synchronized(this)
{
checkClosed();
@@ -176,24 +181,37 @@ public class LPTopGoalIterator implement
* @see com.hp.hpl.jena.util.iterator.ClosableIterator#close()
*/
@Override
- public synchronized void close() {
- if (interpreter != null) {
- synchronized (interpreter.getEngine()) {
- // LogFactory.getLog( getClass() ).debug( "Entering close sync block on " + interpreter.getEngine() );
-
- // Check for any dangling generators which are complete
- interpreter.getEngine().checkForCompletions();
- // Close this top goal
- lookAhead = null;
- //LogFactory.getLog( getClass() ).debug( "Nulling and closing LPTopGoalIterator " + interpreter );
- interpreter.close();
- // was TEMP experiment: interpreter.getEngine().detach(interpreter);
- interpreter = null;
- isReady = false;
- checkReadyNeeded = false;
- nextToRun = null;
-// choicePoints = null; // disabled to prevent async close causing problems
- //LogFactory.getLog( getClass() ).debug( "Leaving close sync block " );
+ public void close() {
+ LPBRuleEngine lpEngine ;
+ synchronized(this)
+ {
+ if ( interpreter == null ) return ;
+ lpEngine = interpreter.getEngine();
+ }
+
+ synchronized (lpEngine) {
+ // Elsewhere code takes an LPBRuleEngine then an LPTopGoalIterator
+ // Ensure we do that lock order here as well as just synchronized
+ // on the method reverses the locks takne, leading to deadlock.
+ synchronized(this)
+ {
+ if (interpreter != null) {
+ // LogFactory.getLog( getClass() ).debug( "Entering close sync block on " + interpreter.getEngine() );
+
+ // Check for any dangling generators which are complete
+ interpreter.getEngine().checkForCompletions();
+ // Close this top goal
+ lookAhead = null;
+ //LogFactory.getLog( getClass() ).debug( "Nulling and closing LPTopGoalIterator " + interpreter );
+ interpreter.close();
+ // was TEMP experiment: interpreter.getEngine().detach(interpreter);
+ interpreter = null;
+ isReady = false;
+ checkReadyNeeded = false;
+ nextToRun = null;
+ // choicePoints = null; // disabled to prevent async close causing problems
+ //LogFactory.getLog( getClass() ).debug( "Leaving close sync block " );
+ }
}
}
}