0

不幸的是,刚开始扩展 APNS 提供程序程序,我对网络协议实现真的很陌生。提供者现在只在一个线程上运行,它只处理少量的通知。现在我想提高其发送比以前更多的能力。我的问题是:

  1. 根据 Apple doc,我可以维护与网关的多个连接。所以我的理解是我在提供程序中运行多线程并在每个程序中维护一个单独的连接。这是正确的吗?

  2. 第一个是对的,对我来说真正的困难来了:我的程序每 5 秒轮询一次队列数据库以检查要发送的新消息。我认为所有线程都轮询同一个数据库不是一个好主意,因为应该有与用户相同的重复消息。如何解决这个问题呢?

我已经看到了连接池,但我真的不明白那是什么。那是我需要学习和使用的东西吗?如果是的话,有人可以简要解释一下它是什么以及如何使用它吗?

多谢你们!

4

1 回答 1

0

Your first assumption is reasonable. Each thread should have its own connection.

As for the second point, the access to the DB that contains the new messages should be synchronized. For example, you can access that DB by a synchronized method that fetches a message or several messages that haven't been processed yet, and marks them as being processed. Two threads can't access that method at the same time, and therefore won't get the same messages.

Another option is to put the messages in memory in a blocking quoue (with the DB only serving for backup in case of a crash). The threads can request an item from the queue, which would block them until an item is available.

于 2013-10-05T17:43:43.797 回答