对象是过程的抽象,线程是调度的抽象;

    分离并发和业务代码:生产者-消费者、读者写者模型、宴席哲学家问题(筷子问题)

  • 互斥
  • 线程饥饿
  • 死锁
  • 活锁

  【调度的体现】

  多线程编程优化的时候,yield有小妙用,马上放弃自己!让出调度

 1  /**
 2      * A hint to the scheduler that the current thread is willing to yield
 3      * its current use of a processor. The scheduler is free to ignore this
 4      * hint.
 5      *
 6      * <p> Yield is a heuristic attempt to improve relative progression
 7      * between threads that would otherwise over-utilise a CPU. Its use
 8      * should be combined with detailed profiling and benchmarking to
 9      * ensure that it actually has the desired effect.
10      *
11      * <p> It is rarely appropriate to use this method. It may be useful
12      * for debugging or testing purposes, where it may help to reproduce
13      * bugs due to race conditions. It may also be useful when designing
14      * concurrency control constructs such as the ones in the
15      * {@link java.util.concurrent.locks} package.
16      */
17     public static native void yield();

 

 

相关文章:

  • 2022-02-16
  • 2022-12-23
  • 2021-08-14
  • 2021-09-08
  • 2021-09-21
  • 2021-07-16
  • 2021-10-10
  • 2021-11-21
猜你喜欢
  • 2021-08-04
  • 2022-01-04
  • 2022-12-23
  • 2021-09-13
  • 2021-07-12
  • 2021-12-18
  • 2021-07-29
相关资源
相似解决方案