0

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; 
} 
}
2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by milil
0

You can use Timer, with timer you can schedule one task to do every 10 secound or any amount of time you need.
Or if you need to wait for something you can use Thread with thread's sleep method to sleep your program for some amount of time and then when he wake up do something...
You need to specify what exacly do you need and we will help with coding. Mike.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.