If one doesn't use Threads or Timers, they wouldn't need synch, as all input/output is handled by a single thread. However, if one introduces TimerTasks, synchronization would be mandatory.
There are two ways to synch the code in J2ME:
- The usual: using locks
- Using
Display.callSerially(Runnable r)
so that all external events would be synched with the Event Thread.
The question is: which way is better or, at least, more widely used? And secondly: if the second way is the preferred one, is the following implementation, reasonable?
class MyTimerTask extends TimerTask {
Display display;
RunnableObject r {
public void run() {
...
}
}
...
public void run() {
display.callSerially(r);
}
}
Thanks!