简体   繁体   English

向Java应用程序通知数据库更改

[英]Informing Java Application about changes in database

I'm trying to build a task-manager application. 我正在尝试构建一个任务管理器应用程序。 Two or more client applications should be able to change (such as mark off or change the title etc) certain tasks stored in the database over the web. 两个或多个客户端应用程序应该能够更改(例如标记或更改标题等)通过网络存储在数据库中的某些任务。

While creating the requirements, the following question came up: 在创建需求时,出现以下问题:

How is it possible to inform client applications (Android Apps, Java-Applications on a Mac) about changes in the database, without constantly checking the database? 在不不断检查数据库的情况下,如何通知客户端应用程序(Android Apps,Mac上的Java-Applications)有关数据库的更改? I planned on storing the data objects in a SQL-Database on a Webserver. 我计划将数据对象存储在Web服务器上的SQL数据库中。 Should I use another database? 我应该使用另一个数据库吗? What is the standard way to go right now in SE world? SE世界中目前的标准方式是什么? Any keywords for me or explanations would help! 对我而言,任何关键字或解释都将有所帮助!

Firstly, make sure you are not accessing the database directly from the client applications, that's a very dangerous route. 首先,请确保您没有直接从客户端应用程序访问数据库,这是非常危险的路线。

Secondly, as for your requirement it looks like you want a server side push notification. 其次,根据您的要求,您似乎需要服务器端推送通知。

As far as I know there are 3 ways to do this. 据我所知,有3种方法可以做到这一点。

  1. Check updates from the server every X seconds (if you don't have too many clients that needs to be notified this way is okay to go) 每隔X秒检查一次服务器更新(如果您没有太多需要以这种方式通知的客户端)
  2. Use HTTP long polling. 使用HTTP长轮询。
  3. Use WebSocket to keep a long lasting connection between server/client applications. 使用WebSocket可以在服务器/客户端应用程序之间保持长期连接。

For mobile devices though, if you want to be notified even when the app is closed, take a look at all the push notification frameworks available out there (eg FCM/GCM). 但是对于移动设备,如果即使关闭应用程序也希望收到通知,请查看那里可用的所有推送通知框架(例如FCM / GCM)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM