package test.test1;public class CompareTest { public static int i = 0; public static int result = 0; public static int a = 0; public static int b = 0; public static void main(String[] args) { new Thread(){ public void run() { while(true){ if(i<100000000){ i++; } else{ i=0; } } }; }.start(); compare(); } public static void compare() { new Thread() { public void run() { a = i; System.out.println("a = "+a); try { Thread.sleep(500); } catch (InterruptedException e) { } b = i; System.out.println("b = "+b); int temp = b-a; System.out.println("差值 = " + temp); }; }.start(); } }
保存当前值的值和时间
当过500毫秒后。在保存一个。比较。
package test.test1;public class CompareTest {
public static int i = 0;
public static int result = 0;
public static int a = 0;
public static int b = 0;
public static void main(String[] args) {
new Thread(){
public void run() {
while(true){
if(i<100000000){
i++;
}
else{
i=0;
}
}
};
}.start();
compare();
} public static void compare() {
new Thread() {
public void run() {
a = i;
System.out.println("a = "+a);
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
}
b = i;
System.out.println("b = "+b);
int temp = b-a;
System.out.println("差值 = " + temp);
};
}.start();
}
}