From: Jomi H. <jom...@gm...> - 2022-06-06 12:08:25
|
Hi Burak, I guess that instructions that change the state of the artifact (obs props/signals) have to be executed in a special way in cartago to avoid breaking its atomicity/transactional features. if a thread of yours is changing the artifact, the change should be executed inside a block beginExternalSession/endExternalSession. In your code, the thread is created inside this block, but the signal is not running inside such a block. Maybe you can move the begin/end… to inside the “run()” method. HTH Jomi > On 5 Jun 2022, at 19:18, Burak Karaduman <bbu...@gm...> wrote: > > Dear all, > > I am trying to create a timer that counts based on seconds. However, I am getting this error; > > java.lang.IllegalMonitorStateException > at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.signalAll(AbstractQueuedSynchronizer.java:1487) > at cartago.Artifact.commitObsStateChangesAndSignal(Artifact.java:573) > at cartago.Artifact.signal(Artifact.java:637) > at example_JaCaMo.MyTimer.access$000(MyTimer.java:11) > at example_JaCaMo.MyTimer$1.run(MyTimer.java:29) > at java.base/java.util.TimerThread.mainLoop(Timer.java:556) > at java.base/java.util.TimerThread.run(Timer.java:506) > > My code is simply like this: > > public class MyTimer extends Artifact { > > void init() { > defineObsProperty("mytimer", 0); > timer_creation(); > } > > void timer_creation() { > this.beginExternalSession(); > > Timer timer = new Timer(); > > TimerTask task = new TimerTask(){ > private int i = 0; > public void run(){ > if (i <= 30) { > signal("timerEnd"); > System.out.println(i); > > } > } > }; > > > timer.scheduleAtFixedRate(task, 0, 1000); //1000ms = 1sec > this.endExternalSession(true); > } > } > > How can I tackle this problem? > > Thank you. > > Best regards. > > > > -- > Burak KARADUMAN, > Ph.D. Student at the University of Antwerp & Flanders Make, > Modeling Intelligent Complex Software & Systems (MICSS-Lab), > G236, Department of Computer Science, Faculty of Science, Campus Middelheim, > Middelheimlaan 1, 2020 Antwerp, Belgium > > _______________________________________________ > Jason-users mailing list > Jas...@li... > https://lists.sourceforge.net/lists/listinfo/jason-users |