将设备数据与Web服务器同步 [英] Sync device data with web-server

查看:94
本文介绍了将设备数据与Web服务器同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有数据,必须根据网络可用性在服务器上对其进行更新.我使用sqlite将这些数据存储在android的本地数据库中.目前的想法是:

I have data in my application which must be updated on the server on the basis of network availability. I store this data on a local database on android using sqlite. Currently the idea is:

  1. 数据应插入本地sqlite数据库中
  2. 服务应在插入数据后立即等待,它会检查网络可用性并将其发送到服务器并等待成功响应.
  3. 如果从服务器收到的响应为true,则应更新该sqlite行的同步状态,然后移至下一行以发送数据.

我想找出对这些数据进行排队以将其发送到服务器的最佳方法,此外,当网络不可用时,该队列应该停止向服务器发送数据.由于Java中有许多队列可用,因此队列是保存此数据的最佳方法.由于数据可以增长到任何无限的大小.这就像一个生产者-消费者问题,但是解决这个问题的最有效方法是什么.

I wanted to find out the best way to queue this data to send it to the server, additionally this queue should stop sending data to the server when the network is unavailable. Since there are lot of queues available in java which queu is the best to hold this data. Since the data can grow to any infinite size. It is a like a Producer-Consumer problem but what is the most efficient way to address it.

谢谢.

推荐答案

为什么已经将这些数据存储在本地数据库中,为什么还要将其存储在队列中呢?我的意思是,如果您的应用程序关闭了,那么队列中的数据就会丢失.只需编写一项检查本地数据库中是否有新条目的服务即可.如果有新条目,请尝试将其推送到Web服务器.

Why would you store this data in a queue when it is already stored in a local database? I mean what happens if your application is shut down then the data in the queue is lost. Just write a service that checks the local database for new entries. If there are new entries try to push them to the webserver.

这篇关于将设备数据与Web服务器同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆