0

I'm programming an app that will display the result of a team. I'd like notify the user when there's a goal. To do this, I created a service where I'll take the score and put it in a String every 30 seconds and I'll create a notification if it changes. My question is: What's the best way to repeat this every 30 seconds ?

Thank's and sorry for my poor english

4

2 回答 2

2

好吧,如果您想每 x 秒进行一次调用,则需要ajax setTimeout (而不是 setInterval)。如果您要这样做,最好在每次往返时将一些数据发送回数据库,以确保您的查询不是大量的,并搜索整个数据库表。

例如,您可能会在每次往返时发回最新的时间戳。然后让后端查询检查有多少行大于该时间戳并向用户显示计数。因此,如果只有一行,则显示 user 1 new row。当他们点击它查询内容时。这应该是对高影响活动的低影响查询(池将是更好的选择)。祝你好运。

PS:如果你今晚想变得花哨并真正学习一些东西,我会做一些关于异步 servlet的研究,而不是像另一张海报建议的那样只是汇集。这会带你进入兔子洞,找到一些非常甜蜜的东西。

于 2013-04-30T07:55:46.567 回答
0

您可以执行以下操作:

  • 检查是否有任何变化(是 - 发送新信息,不 - 什么都不做)
  • 睡眠 30 秒 ( Thread.sleep(30000))
  • 重复
于 2013-04-30T07:58:51.057 回答