From: Burak K. <bbu...@gm...> - 2022-06-06 14:37:45
|
---------- Forwarded message --------- Gönderen: Burak Karaduman <bbu...@gm...> Date: 6 Haz 2022 Pzt, 16:36 Subject: Re: [Jason-users] Create a timer based on seconds in Cartago To: Jomi Hubner <jom...@gm...> Hi Jomi, I had solved my problem as you suggested. Thank you so much for your help. I share the solution I hope it can help others in the future. * this.beginExternalSession(); commit(); this.endExternalSession(false);* However, I have another question, I have a function which is encapsulated inside an artefact namely getUDPMessage(). However, this should be continuously checked in case of data is sent anytime. Is it possible to attach a feature for continuously listening a function of an artifact? Best regards. Jomi Hubner <jom...@gm...>, 6 Haz 2022 Pzt, 14:08 tarihinde şunu yazdı: > 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 > > -- *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 -- *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 |