即时消息

编程入门 行业动态 更新时间:2024-10-23 17:34:28
即时消息 - Java上的单一连接或多线程(Instant messaging— single connection or multithreading on Java)

我应该在关键时间的应用程序中向一组联系人发送即时电子邮件。

说,我在列表中有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/…

更多推荐

本文发布于:2023-07-31 02:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:即时消息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!