I want to get the last updated time of a variable.
static Date ti;
for (int i = 0; i <= attachedControllers.length; i++ )
{ ti = null;
controllers tempc = attachedControllers[i];
ti = tempc.getLastUpdated(); // return the last updated time of each controllers object.
System.out.println("last updated of \t" + tempc.getControllerName() +"is \t"+ti);
Date t2 = new Date();
System.out.println("Time now \t" + t2);
long s = (t2.getTime() - ti.getTime())/(1000 * 60 );
System.out.println("difference is \t"+s);
}
the problem is the variable ti stores all previous values of the last updated time of each controllers object. and I want to get the last value only. the output here is:
last updated of 0.0.0.0/0.0.0.0:6632is Sun Jun 21 03:38:59 AST 2015
Time now Sun Jun 21 03:39:14 AST 2015
difference is 0
last updated of 0.0.0.0/0.0.0.0:6633is Sun Jun 21 03:39:04 AST 2015
Time now Sun Jun 21 03:39:19 AST 2015
difference is 0
last updated of 0.0.0.0/0.0.0.0:6632is Sun Jun 21 03:38:59 AST 2015
Time now Sun Jun 21 03:40:14 AST 2015
difference is 1
last updated of 0.0.0.0/0.0.0.0:6633is Sun Jun 21 03:39:04 AST 2015
Time now Sun Jun 21 03:40:19 AST 2015
difference is 1
last updated of 0.0.0.0/0.0.0.0:6632is Sun Jun 21 03:40:59 AST 2015
Time now Sun Jun 21 03:41:14 AST 2015
difference is 0
last updated of 0.0.0.0/0.0.0.0:6632is Sun Jun 21 03:38:59 AST 2015 // here it retrieve the first value of last updated time which is my problem.
Time now Sun Jun 21 03:41:14 AST 2015
difference is 2
last updated of 0.0.0.0/0.0.0.0:6633is Sun Jun 21 03:39:04 AST 2015
Time now Sun Jun 21 03:41:19 AST 2015
difference is 2
I call this this function like this:
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
exec.scheduleAtFixedRate(new Runnable()
{
public void run()
{
checkControllerHealth ();
}
}, 15, 60, TimeUnit.SECONDS);
Then put outside of your loop the
System.out.println
. Like this:Then it will show only the last iteration that you have in your loop.
I expect it will be helpful for you!