我应该在关键时间的应用程序中向一组联系人发送即时电子邮件。
说,我在列表中有n个联系人。 所以,我可以做以下任何一种情况:
i。)向所有这n个联系人发送一封电子邮件作为多个接收者。
ii。)在n个线程中为每个接收者分别发送一封电子邮件。
在第一种情况下,我在我的端部建立一个连接,然后将其发送出去。
在第二个,连接到我的smtp服务器。 但是,它是并发的。
哪一个更快?
I'm supposed to send out instant emails to a set of contacts in a time-critical application.
Say, I have n contacts in the list. So, i can do either one of the following:
i.) send out a single email to all of these n contacts as multiple receivers.
ii.)send n emails, separately one for each receiver, in n threads.
In the first case, i'm setting up a single connection at my end and just sending it out.
In the second, n connections to my smtp server. However, it is concurrent.
Which one is faster?
最满意答案
电子邮件不是为即时消息而设计的。 如果您想要即时消息,则需要p2p类型的连接。 如果您打算使用电子邮件,而不管您将如何发送电子邮件,则会有太多其他因素干扰。 通常第一种方法会(稍微)更快,因为它将允许邮件服务器优化消息的发送方式。
请参阅ServerSocket() http://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html和Socket()docs.oracle.com/javase/7/docs/api/java/net /Socket.html
如果您需要保证交付,如果速度更重要且服务器/客户端在同一网络上,您可能需要查看MulticastSocket http://download.java.net/jdk7/archive/b123,您将需要如上所述的p2p / docs / api / java / net / ...
email are not designed to be instant messaging. If you want instant messaging you need p2p type of connection. If you intend to use emails than it does not matter how you will send them, too many other factors will interfere. Generally 1st method will be (marginally) faster as it will allow mail server to optimise the way the messages are sent.
See ServerSocket() http://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html and Socket() docs.oracle.com/javase/7/docs/api/java/net/Socket.html
Again you will need p2p as above if you need guaranteed delivery, if speed is more important and the server/client are on the same network you may want to look at MulticastSocket http://download.java.net/jdk7/archive/b123/docs/api/java/net/…
更多推荐
发布评论