Albus Dumbledore
Albus Dumbledore

Reputation: 12616

Synchronization in J2ME

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:

  1. The usual: using locks
  2. 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!

Upvotes: 0

Views: 603

Answers (1)

Mahdi Hijazi
Mahdi Hijazi

Reputation: 4454

I prefer the second one, it is more clear to me. I can't see anything wrong with your implementation, I think you can use it safely.

Upvotes: 1

Related Questions