偶数线程
| 45 | * 偶数线程 |
| 46 | */ |
| 47 | public static class OuNum implements Runnable { |
| 48 | |
| 49 | private TwoThread number; |
| 50 | |
| 51 | public OuNum(TwoThread number) { |
| 52 | this.number = number; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void run() { |
| 57 | while (number.start <= 1000) { |
| 58 | |
| 59 | if (number.flag) { |
| 60 | try { |
| 61 | LOCK.lock(); |
| 62 | System.out.println(Thread.currentThread().getName() + "+-+" + number.start); |
| 63 | number.start++; |
| 64 | number.flag = false; |
| 65 | |
| 66 | |
| 67 | } finally { |
| 68 | LOCK.unlock(); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * 奇数线程 |
nothing calls this directly
no outgoing calls
no test coverage detected