添付のコードを使用して、5 分ごとにデータベースに情報を送信します。情報の一部はタイムスタンプです。データベースを見ると、6 分の差や 7 分の差があるレコードが表示されますが、どうしてでしょうか? 私の仕事は時間がかかりすぎると言う人もいました。
とにかく私の質問は、5 分ごとに情報をデータベースに送信するようにコードを強制する方法です。
*重要なことは、タスクに条件があることです。つまり、タスクが実行されない場合があるため、レコード間の差は 5 の倍数である必要があります。
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);
}
}
}
}
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();
}