开发者

how to synchronize base class

i have extend a uiapplication for user interface,in which i will take a date on which i schedule a task. and i extend another base class application for running ba开发者_如何转开发ckground process which will check the date and execute desired operation. but these both are base class so i want to synchronize them.. and don't know how to synchronize base class.. plz help mee..


First, and I know it is a fine point but programming is all about fine points, you don't synchronize on Classes, you sychronize on Objects (which are instances of Classes).

On Blackberry you can use standard Java sychronization techniques, synchronized methods:

public synchronized void mySynchronizedMethod() {
   // synchronized code
}

and synchronized blocks:

public void myMethod() {
   //code
   syncrhonized(someObject) {
      // synchronized code
   }
   // code
}

You can also use a specific object to synchronize with the event thread and have your code run on the event thread which allows serialized access to the UI:

public void myMethod() {
   //code
   syncrhonized(UiApplication.getEventLock()) {
      // synchronized code
   }
   // code
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜