Multi-threaded and characteristics

  1. A thread is smaller than the process of execution units. Multithreading: refers to the presence of several executable simultaneously in the same program, the situation according to several different execution paths to work together.
  2. State of the thread of the life cycle:
    5 states (1) of threads: new, ready, running, blocking and die.
    New state: When a thread after the object is declared and created in the new state. Available () method goes into a ready state by the start.
    Ready state: thread queue waiting to enter the system allocates CPU for it, and once we have CPU, the thread enters running.
    Operating status: automatically execute their own code run method.
    Blocking state: a thread being executed in some special cases, such as the implementation of the suspend, join or sleep methods, or wait for the right to use the I / O devices, and it will allow the CPU to suspend their execution, enter obstruction status. Only when the cause of obstruction is removed, the thread can only be transferred to a ready state.
    The demise of the state: the thread is the demise of the state does not have the ability to continue to run.
  3. Both methods achieve multi-threaded:
    (1) inheritance Thread class (Thread class implements Runnable interface)
    (2) implement Runnable (only one way to run ())
  4. Thread subclass establish and implement Runnable can create multiple threads. But Runnable interface can easily use multiple threads share the same data, as long as the same class of an object that implements Runnable interface as an argument to create multiple threads on it.
  5. Multi-thread synchronization control
    in any case, there can be synchronized only one thread calls a particular object. When you call any synchronized method of an object, the object is locked, you can no longer call any other synchronized method of the object.
发布了43 篇原创文章 · 获赞 8 · 访问量 2377

Guess you like

Origin blog.csdn.net/username666/article/details/103943152