[rules-users] infinite loop controlling

Isabelle Hupont ihupont at ita.es
Tue Oct 23 04:27:55 EDT 2007


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.




More information about the rules-users mailing list