📄 test.java
字号:
package com.test;
public class Test {
int index = 1000;
public synchronized void out(int i) {
int k = index;
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
k = k - i;
index = k;
}
public void in(int i) {
synchronized (this) {
int k = index;
k = k + i;
index = k;
}
}
public static void main(String[] args) {
Test t = new Test();
ThreadTest t1 = new ThreadTest("Thread1", t);
ThreadTest2 t2 = new ThreadTest2("Thread2", t);
// t1.setPriority(5);
// t2.setPriority(5);
t1.start();
t2.start();
while (t1.isAlive() || t2.isAlive()) {
}
System.out.println("index:" + t.index);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -