【设计篇】线程与并发
对象是过程的抽象,线程是调度的抽象;
分离并发和业务代码:生产者-消费者、读者写者模型、宴席哲学家问题(筷子问题)
- 互斥
- 线程饥饿
- 死锁
- 活锁
【调度的体现】
多线程编程优化的时候,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();
--------------------------------
优秀、是一种习惯
、、、、、、、、、、、、、、、

浙公网安备 33010602011771号