I use the attached code to send to my db every 5 min some information, some of the information is timestamp. When I look in my db I see records with 6 minute diffrence and even 7, how come? Some told me that my task takes too long.
我使用附加的代码每隔5分钟向我的数据库发送一些信息,其中一些信息是时间戳。当我查看我的数据库时,我看到记录有6分钟差异,甚至7分钟,怎么样?有些人告诉我,我的任务需要太长时间。
Anyway my question is how I can force my code to send the info the to the db every 5 min.
无论如何,我的问题是如何强制我的代码每隔5分钟将信息发送到数据库。
*Important thing I have to say that I have a condition on the task which means that sometimes it won't do a thing so the diffrence between the records should be multiples of five.
*重要的是我必须说我对任务有一个条件,这意味着有时它不会做任何事情,所以记录之间的差异应该是五的倍数。
this.timer.schedule(new Send(), new Date(), TEN_SECONDS*6*5);
class Send extends TimerTask
{
public void run()
{
if(location!=null)
{
if (mGeocoderAvailable)
address = reverseGeocode(LocationService.this.location);
if(address != "" && !address.equals(lastAddress))
{
lastAddress = address;
new SendLocation(LocationService.this.id,address);
}
}
}
}
The SendLocation body is like this:
SendLocation主体是这样的:
public SendLocation(int id,String address)
{
// taking care the parameters
this.start();
}
public void run()
{
//connect to db
//send location to db
this.destroy();
}
1 个解决方案
#1
0
The time was scheduled inside the SendLocation thread instead from the Send task.
时间安排在SendLocation线程内,而不是Send任务。
#1
0
The time was scheduled inside the SendLocation thread instead from the Send task.
时间安排在SendLocation线程内,而不是Send任务。