来自 Web 服务的推送通知 [英] PUSH Notifications from a Web service

查看:53
本文介绍了来自 Web 服务的推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络服务,可以定期在数据库中存储移动用户的位置.我现在想尝试将 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.

推荐答案

完成此任务的步骤 -

  1. 创建一个 servlet 并在部署描述符中注册它
  2. 覆盖servlet
  3. init方法
  4. 创建一个线程并在init 方法中启动它.使用while循环无限执行来做监控任务
  5. 最重要 - 通过将以下行添加到部署描述符中,在服务器启动期间强制 servlet 初始化.此链接中的信息 - http://jersey.576304.n2.nabble.com/Initialization-at-startup-as-opposed-to-first-request-td5164440.html
  1. Create a servlet and register it in the deployment descriptor
  2. Override the init method of the servlet
  3. Create a thread and start it in the init method. Use a while loop to execute infinitely to do the monitoring task
  4. 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屋!

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