Hi! I'm developing a software where the user creates his own rules, saves then, and finally fires them in order to preprocess a set of data. I have implemented a method for controlling infinite loops (its simply a timer). I would like to notify to the user the rule that has caused the infinite loop, in order to change it. My code is the following:
public void fireRules(Instances instances) { try { assertInstances(instances); // Worker thread to execute task that may hang. WorkerThread workerThread = new WorkerThread(); // Wait for timeout or task end. synchronized (this) { workerThread.start(); try { this.wait(60000); } catch (InterruptedException e) { log.error(e.getLocalizedMessage(),e); } if (!workerThread.isWorkDone()) { // If work is not done then workingMemory.fireAllRules() // hasn't finished (the timeout has expired). workingMemory.halt(); // Here comes the code for capturing rule that has code the loop throw new PersistenceException("Operation timeout. Please modify rule XXX" ); } } cleanWorkingMemory(); } catch (PersistenceException e) { log.error(e.getLocalizedMessage(),e); } log.debug("Rule firing finished"); } private class WorkerThread extends Thread { private boolean workDone = false; public boolean isWorkDone() { synchronized (SingletonInferenceEngine.this) { return workDone; } } public void run() { workingMemory.fireAllRules(); synchronized (SingletonInferenceEngine.this) { workDone = true; SingletonInferenceEngine.this.notifyAll(); } } } Can you help me? Thanks in advance! -- View this message in context: http://www.nabble.com/infinite-loop-controlling-tf4675899.html#a13359512 Sent from the drools - user mailing list archive at Nabble.com. _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users