|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#9
|
|||
|
|||
|
Re: Configure Timers
Quote:
Especially when I run embedded code on an operating system that doesn't guarantee timing, I always put code in in there to monitor the execution of each state. Unfortunately, the SwawkOS doesn't support : Code:
System.nanoTime() Code:
System.currentTimeMillis(); Quote:
Something like: Code:
this.executor = new java.util.Timer(); this.executor.schedule(new MyTimedTask(this), 0L, this.period); Code:
while(true)
system.out.println("Hello World");
However, for JavaFRC you can use other properties of the Timer Task to control your concurrancy. For example you could use the scheduleAtFixedRate method of the TimerTask, which i believe does preempt the running thread to try and guarantee execution. (I never tested it however). The better way to do it in a normal J2ME project would be to set the priority of all of your threads. Using the Thread.setPriority() and Thread.getPriority() functions and the Thread.xxPRIORITY static fields. You can have up to 10 levels of priorities. Where Higher priorities will pre-empt lower ones. However these methods are not supported by Squawk JVM for FRC, and all threads in FRC Java are created with the same NORMAL priority. The best way to do it JavaFRC would be to avoid the need for preemption and try to ensure your code is optimized and runs in a period that is reasonable so that the CPU can be shared between all normal priority tasks. If all of your JavaFRC threads have relatively small execution times compared to its period, (and they should), then all your threads should have enough access to the CPU to run within its within its periodicity. Java VM in general is not a real time OS, so timing is never truly guaranteed, no matter what we do. Most of the inconsistencies arise when you have threads that are relying on preemptive behavior, instead of cooperatively giving up CPU time. Hope that helps, - Kev Last edited by NotInControl : 02-04-2013 at 02:47 AM. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|