PUSH Notifications from a Web service

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 06:56:23

问题


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?

Will creating a thread to do the monitoring task in the constructor of the web service help to maintain a constant monitor?

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:


Steps to accomplish this task -

  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


来源:https://stackoverflow.com/questions/26735941/push-notifications-from-a-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!