比较不同时刻的相同功能输出

时间:2016-09-07 11:52:38

标签: java multithreading

我在相同的功能输出之间进行比较时遇到了麻烦。

public int Get_CSV_number_lane()
{
   return csvfile.numberlane(); //this func return number of lane in csv file
}

在我的主要表单中,我想保存此值并打开Thread。此Thread检查if (old saved value != new value){do something}

int number_of_lane = Get_CSV_number_lane();

Thread()
{
    if(number_of_lane != Get_CSV_number_lane())
    {
       println("number of lane changes");
       number_of_lane = Get_CSV_number_lane();
    }
}

我有一个返回CSV文件行的函数。在执行期间,此文件可以更改。我有Thread检查旧值(开始时的CVS行)是否与新值(现在的CSV行)不同并执行某些操作。问题是这个检查:旧值始终是新值。

我的问题是,如何解决这个问题,如何存储旧值并检查新值?

1 个答案:

答案 0 :(得分:0)

如果您熟悉ExecutorService,则可以使用类似的类型 - ScheduledExecutorService:An ExecutorService that can schedule commands to run after a given delay, or to execute periodically.使用ScheduledExecutorService,您可以启动一个线程来定期检查您的值,然后您可以将其与旧值进行比较。以下是如何使用ScheduledExecutorService

的教程