GDC Class Notes

Class Notes of Graduate Diploma in Computing in Unitec

Thread on Android

Thread thread = new Thread()
{
public void run()
    { //some codes here
    }
};
thread.run()

Some mistakes learners made

  • thread.start(), not use run directly
  • reading from different thread is OK, writing might be a problem

Some tips

  • threads that have dead cannot be restarted
  • lot of problmes of reading/writing

Race conditions

  • execution of threads is not-deterministic
  • executation order effects outcome
  • program may run correctly 99.99%ek5

  • no problem if you are just reading shared data

synchronized

  • only one thread can access this object or the execute this section of code one time
  • other threads will wait
  • can solve non-deterministic issues during runiing

Dead lock

  • two or more threads are locked forever - waiting to acquire locks to shared objects that each thread has a lock against
  • a circular dependacy between threads and locks