javaagents-jademulti-agent

WakerBehaviour gets blocked by other activities


I am working on a multi-agent system in JADE and use WakerBehaviours to simulate events. However, in some cases, the WakerBehaviour wakes up much too late which leads to problems. I have tested this in the following code, but the "Im awake"-message always pops up, AFTER the while-loop is completed. how could i avoid this?

public class Test_Agent extends Agent {
protected void setup() {
    Tools.prnt(this, "starting waker");
    addBehaviour(new TickerBehaviour(this, 1000) {
        protected void onTick() {
            Tools.prnt(myAgent, "Im awake.");
        }
    });
    int i = 0;
    while(i < 100000) {
        System.out.println(i+" waiting.");
        i++;
    }   
}

Thanks in advance! Cheers, Jacek


Solution

  • As far as I know, processing of behaviours starts after setup(). that is why you should move loops inside a behaviour and If you want to handle events during loop, avoid loops and use cycle behaviour (because behaviours is processed in turn).