r
运行队列中进程数量
-b
等待io的进程数量
so 每秒从内存写入磁盘的交换页数量 kb/s
bi
每秒读取的块数
频繁切换上下文
import java.util.Random; /** * @version 1.0 * @author: mousycoder * @date: 2019-07-18 15:24 */ public class HoldLockMain { public static Object[] lock = new Object[10]; public static Random r = new Random(); static { for (int i = 0; i < lock.length; i++) { lock[i] = new Object(); } } public static void main(String[] args) { for (int i = 0; i < lock.length * 2; i++) { new Thread(new HoldLockTask(i / 2)).start(); } } public static class HoldLockTask implements Runnable { private int i; public HoldLockTask(int i) { this.i = i; } @Override public void run() { try { while (true) { synchronized (lock[i]) { if (i % 2 == 0) { lock[i].wait(r.nextInt(10)); } else { lock[i].notifyAll(); } } } } catch (InterruptedException e) { e.printStackTrace(); } } } }
输出 vmstat 1 4
可见上下文切换频繁