A class gets a rapidly changing integer from another class. As it changes so fast, I wanted to perform an action only when this number is stabilized. Like if the method receives the same integer value during 3 seconds, then perform an action, otherwise ignore it as it changes too fast. Can someone tell me how to do it? best way?
The thing is, other methods should not be stopped unless this time passes.
this is what I did and doesn't work as expected.
public static void main(String[] args)
{
boolean t=false;
long cuTime = System.currentTimeMillis();
while(t==false)
{
System.out.println(cuTime);
long g=cuTime+2000;
long ct2=System.currentTimeMillis();
if(ct2>=g)
{
System.out.println(ct2-cuTime);
//action here
t=true;
}
}