Thursday 5 February 2015

When to use Threads



Thumb rule to use Threads in the code

  1. If the operation (i.e. the method) that needs to be called is provided by external system (i.e. operation not belonging to your project).
  2. If the execution time of operation is unknown or big
  3. If the operation is not an UI related.
    • If the operation is UI related, typically it has to be run in the UI thread.
    • Never launch a thread and call the UI operations from it. Though many framework provides context switchers to call the UI operations from another thread, it should be typically avoided in most of the case.

Eclipse Tip: In Eclipse,

@Inject UISynchronize uiSync (asynExec/syncExec)

are the methods used to change the context to the UI thread. They have to used rarely. In many cases, the usage of them indicates a design code smell and possibly a refactoring is needed.

No comments:

Post a Comment

Gallery

Object Oritented, Git

Most Commented

OOAD

Contact Form

Name

Email *

Message *

2014 © Planer - Responsive Blogger Magazine Theme
Planer theme by Way2themes