Tuesday 2 August 2011

Multiple Threads

Be careful !!!!

Computers with strong CPU and huge memory will cause programmers use multiple threads to speed their programs. Multiple thread is necessary.
  • put some calculation to the background
  • put an unsave thread to a separate thread 
Creating threads:

import java.lang.*;public class Counter extends Thread
{                     
        public void run()                      
        {             
        ....           
        }


}

or

import java.lang.*;
public class Counter implements Runnable
{
        Thread T;                       
        public void run()                      
        {                             
        ....           
        }
}

Be careful !!!

Be careful of your multiple threads!!!!   Sometimes, they may cause problem, especially in GUI.

Example:

When pop up a dialog box, and change the screen orientation, the screen will no respone. After review and chang some multiple threads, the bug is disappeared.




 Reason:

The dialog box will stop all the threads, some GUI threads also will stop. This causes the screen no respone.

Conclusion:

Use multiple threads is necessary, but be careful.