this week we have a good understanding of threading, master two ways to create threads, the first: inherit the thread class,
Rewrite the Run method and write the code to execute in the Run method. The child class object is passed in when the thread object is created. The second type:
Implement the Runable interface and override the Run method. The subclass object that is passed in to the interface when the thread object is created.
When multiple threads start at the same time, each thread will probably have five states, in order to avoid the uncertainty of multi-threaded startup
Usually solved by means of locks and synchronized.
Currentthread.getname (); The method can get the name of the current thread in multithreaded development.
There are some differences between sleep and wait:
1.sleep method must set the time for thread hibernation
The wait method can either be established or not specify the time at which the thread stops.
The 2.sleep method does not release the monitor lock permission when it is executed, and is in a temporary blocking state.
The Wait method releases the lock permission immediately after execution
3.sleep method automatically wakes up after time and continues execution
The wait method waits after execution if it has not been notify or Notifyall wake.
4.sleep methods are not necessarily defined in synchronization
The wait method must be used in the synchronization
We can also use the SetPriority method to prioritize threads.
201671010138 2016-2017 "Java Programming"