来自 Web 服务的推送通知 [英] PUSH Notifications from a Web service
问题描述
我有一个网络服务,可以定期在数据库中存储移动用户的位置.我现在想尝试将 push
通知从网络服务发送到 Android 应用.我知道这可以使用 Android 版 GCM 来实现.
I have a web service that stores locations of a mobile user in the DB periodically. I now want to try sending push
notifications from the web service to the Android app. I understand that this can be achieved using GCM for Android.
但是,我不确定如何运行一个持续监控数据库的进程.有人可以建议我如何实现这一目标吗?
However, I am not sure how I can run a process that continuously monitors the DB for a condition. Can somebody suggest how I can achieve this?
在Web服务的constructor
中创建一个thread
来完成监控任务是否有助于保持持续监控?
Will creating a thread
to do the monitoring task in the constructor
of the web service help to maintain a constant monitor?
PS:目前我正在启动一个线程,当应用程序调用 store 方法然后将 POST
请求发送到 GCM 服务器以推送通知时,它将检查数据库中我需要的条件条件满足.
P.S: At the moment I am just starting a thread which will check the DB for the condition I need when the app calls the store method and then sends POST
request to GCM server to push notifications if the condition is satisfied.
推荐答案
完成此任务的步骤 -
- 创建一个
servlet
并在部署描述符中注册它 - 覆盖servlet 的
- 创建一个线程并在
init
方法中启动它.使用while
循环无限执行来做监控任务 - 最重要 - 通过将以下行添加到部署描述符中,在服务器启动期间强制 servlet 初始化.此链接中的信息 - http://jersey.576304.n2.nabble.com/Initialization-at-startup-as-opposed-to-first-request-td5164440.html
init
方法- Create a
servlet
and register it in the deployment descriptor - Override the
init
method of the servlet - Create a thread and start it in the
init
method. Use awhile
loop to execute infinitely to do the monitoring task - Most important - force the servlet initialization during server startup by adding the following line to the deployment descriptor. Info at this link - http://jersey.576304.n2.nabble.com/Initialization-at-startup-as-opposed-to-first-request-td5164440.html
这篇关于来自 Web 服务的推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!