Create a multithreaded several ways, how threads deadlock, how to prevent the thread deadlock

Way:
  inheritance Thread re-run method to achieve Runnable interface Callable Interface
Expansion:
  Callable and Runnable difference:
  Runnable no return value, callable can get a return value.
  callable can be seen as complementary runnable

Produced:
  a resource can only be a process using
  one of causing obstruction due to multiple requests, maintaining a hold of the resources have been accessed
  process has acquired the right to use the resources, but have not used
  the same process, the frequent access to resources the right to use, has not been released
to prevent:
  locking sequence (thread locking in a certain order)
  lock time (when the thread tries to acquire the lock, plus a certain period of time, exceeds the time limit, then give up lock on the resource)
  deadlock detection (usually it all the locks are on the map, the lock detection map)
expansion:
  the difference between threads and processes:
    a program has at least one process, a process has at least one thread; a process can have multiple thread, to increase the execution speed of the program.
  What is daemon thread:
    daemon thread is a special case of the background process, which is independent of the control terminal, and periodically perform some task or pending certain events happening in the java kinds of
  garbage collection is a special kind of daemon thread.
Thread which states:
  new new has not yet started
  Runnable being executed
  blooked blocked, (the synchronization lock, or lock blocking io)
  Waiting permanent wait state
  time_waiting waiting for a specified time, re-awakened state
  terminated (US blow Nate) execution is complete
sleep and wait a difference:
  Different classes: sleep from Thread wait Object from
  releasing the lock: sleep need not release the lock, wait need to manually release the
  usage of different: sleep time to wake up after an automatic, wait can notify () notifyAll () directly wake.
notify and notifyAll difference
  notifyAll wakes up all waiting threads, notify a wake
  after notifyAll call, all waiting threads to wait by the pool, move lock pool, the lock and then participate in the competition, the winner of the competition to continue, if not successful then continue stay in the lock pool, to continue to compete after waiting for the lock release.
  notify a wake, which is specific, this is controlled by a virtual machine.

Guess you like

Origin www.cnblogs.com/hacker-lsr/p/11787223.html