Closed sdalgard closed 9 years ago
The section
try {
Thread.sleep(' & m.delay & ');'
timer!timer_timeout()
'} catch (Exception ex) {
}
is dangerous. It catches not only InterruptedException
and you never know that it catched an exception. Helpful is at least to print a message which exception was catched.
I agree that code is not perfect. I previously used Java Timer and TimerTasks, but it was a bit heavy for realizing a simple timer. Now I just use a simple Thread, but have to deal with some lower level issues. I will try to make it better.
OK, I revised the timer, which should provide more useful feedback in case the internal thread is interrupted (which is normal if you cancel the timer). It should also be somehow more robust.
@sdalgard can you try it and close the issue if it is good enough for your case?
Works well for my applications :+1:
It seems that the send method for some reason throws exception.....
<*** Snip from console printout **> Sender:0 sends token:5 Ender:0 got token:5 Sender:0 sends token:7 Ender:0 got token:7 Sender:0 sends token:5 Ender:0 got token:5 java.lang.InterruptedException: sleep interrupted at java.lang.Thread.sleep(Native Method) at java.lang.Thread.sleep(Thread.java:340) at org.thingml.java.Component.send(Component.java:66) at org.thingml.generated.TimerJava.sendTimer_timeout_via_timer(TimerJava.java:44) at org.thingml.generated.TimerJava.access$000(TimerJava.java:21) at org.thingml.generated.TimerJava$1$1.run(TimerJava.java:119)
Sender:0 sends token:6 Ender:0 got token:6 java.lang.InterruptedException: sleep interrupted at java.lang.Thread.sleep(Native Method) at java.lang.Thread.sleep(Thread.java:340) at org.thingml.java.Component.send(Component.java:66) at org.thingml.generated.TimerJava.sendTimer_timeout_via_timer(TimerJava.java:44) at org.thingml.generated.TimerJava.access$000(TimerJava.java:21) at org.thingml.generated.TimerJava$1$1.run(TimerJava.java:119)
Sender:0 sends token:8 Ender:0 got token:8 Sender:0 sends token:7 Ender:0 got token:7 Sender:0 sends token:9 Ender:0 got token:9 java.lang.InterruptedException: sleep interrupted at java.lang.Thread.sleep(Native Method) at java.lang.Thread.sleep(Thread.java:340) at org.thingml.java.Component.send(Component.java:66) at org.thingml.generated.TimerJava.sendTimer_timeout_via_timer(TimerJava.java:44) at org.thingml.generated.TimerJava.access$000(TimerJava.java:21) at org.thingml.generated.TimerJava$1$1.run(TimerJava.java:119)
Sender:0 sends token:6 Ender:0 got token:6 Sender:0 sends token:10