【发布时间】:2022-12-09 02:05:11
【问题描述】:
我正在寻找一种方法来从另一个正在运行的类中获取变量的值,因为该类正在更新变量
我基本上是尝试分块复制文件,但是如何更新不同 java 类的进度
所以基本上:
类复制文件变量复制数据 --> 检查进度类变量显示进度
我是 java 的新手,所以我已经犯了很多错误
public class Class_one
{
public static void main(String[] args) throws InterruptedException {
Class_three class_three = new Class_three();
while(true) {
Class_one class_one = new Class_one();
long test = class_three.data();
System.out.println(test);
}
}
}
public class Class_two {
public static void main(String[] args) throws InterruptedException {
Class_three class_three = new Class_three();
class_three.generatea();
}
}
public class Class_three {
public static long a ;
public long c ;
public void generatea() throws InterruptedException {
for (long b = 0 ; b < 100000000000L; b++){
Thread.sleep(1000);
a = b;
System.out.println("generatea : " + a);
//this.c++;
}
}
public long data() throws InterruptedException {
long b = a;
System.out.print("a : " + "\tb : " + b);
return b;
}
}
所以 Class_one 需要能够获得全局 a 的 Class_three 值,但 Class_two 正在运行 Class_Three
希望这是有道理的
【问题讨论】:
标签: java