在Web应用程序之间使用java邮件消息对象

时间:2021-04-30 18:08:16

I'm developing a web application which acts as an email client for mobile. In this application user can login and provide numerous email ids for monitoring.There are two main classes in the web application. 1.MailGetter 2.MailFormatter

我正在开发一个Web应用程序,它充当移动电子邮件客户端。在此应用程序中,用户可以登录并提供大量电子邮件ID以进行监控.Web应用程序中有两个主要类。 1.MailGetter 2.MailFormatter

Behaviour of MailGetter class:

MailGetter类的行为:

  1. Timertask initiated which will execute for every 10 minutes
  2. Timertask启动,每10分钟执行一次

  3. Obtains the numerous email ids from database which are provided for monitoring
  4. 从数据库中获取许多用于监视的电子邮件ID

  5. establishes connection with mail server for the first email id and obtains recently arrived email message object
  6. 与邮件服务器建立第一个电子邮件ID的连接,并获取最近到达的电子邮件对象

  7. passes the message object to MailFormatter class
  8. 将消息对象传递给MailFormatter类

Behavior of MailFormatter class:

MailFormatter类的行为:

  1. parses the email message object
  2. 解析电子邮件消息对象

  3. various recursive calls made if the message has many multiparts inorder to parse parts one by one
  4. 如果消息具有许多多部分以便逐个解析部分,则进行各种递归调用

  5. downloads also attachments along with this message
  6. 下载附件以及此消息

  7. returns an xml string to the MailGetter class which will be stored as simple text file with the following content:
  8. 将一个xml字符串返回给MailGetter类,该类将存储为具有以下内容的简单文本文件:

Example:

<mail>
<from>FromEmailID</from>
<to>ToEmailID</to>
<subject>Subject</subject>
<body>Email Body</body>
<attachments>
  attachment
</attachments>
</mail>

MobileResponderServlet: A separate servlet is also coded in the web application which will read the simple xml text file and send the read content to mobile

MobileResponderServlet:Web应用程序中还编写了一个单独的servlet,它将读取简单的xml文本文件并将读取的内容发送到移动设备

The main demerit of this application might be "MailGetter" class will be waiting until all the functions (including recursive calls) of "MailFormatter" class finishes execution.Once the control is returned from "MailFormatter" class to "MailGetter" class, it will obtain the next message object from mail server and passes it to "MailFormatter" class.So intimating about new emails to the mobile user consumes time. Even when "MailFormatter" class is implemented as a separate thread,consider in a case if there are 1000 new emails in a single inbox (for a single emailid) which will be invocating 1000 "MailFormatter" threads, which will make the process more resource intensive.

这个应用程序的主要缺点可能是“MailGetter”类将等待“MailFormatter”类的所有函数(包括递归调用)完成执行。一旦控件从“MailFormatter”类返回到“MailGetter”类,它将从邮件服务器获取下一个消息对象并将其传递给“MailFormatter”类。因此,向移动用户发送新电子邮件时会消耗时间。即使将“MailFormatter”类实现为单独的线程,也要考虑在一个收件箱(对于单个emailid)中是否有1000个新电子邮件,它们将调用1000个“MailFormatter”线程,这将使该进程获得更多资源密集。

So I'm deciding to unplug "MailFormatter" from "MailGetter". "MailGetter" will be running as a separate web application in one server whereas "MailFormatter" will be running as a separate web application in another server. After obtaining the recent email message object "MailGetter" web application persists (via message.writeTo(FileOutputstream)) the message object in a location which is also common to "MailFormatter". "MailFormatter" class then reads (via MimeMessage(Session,InputStream) constructor) and parses the message object one by one and then stores the "XML Content" in another location which will be read by "MobileResponderServlet" and sent to mobile.

所以我决定从“MailGetter”中拔掉“MailFormatter”。 “MailGetter”将作为单独的Web应用程序在一个服务器中运行,而“MailFormatter”将作为另一个服务器中的单独Web应用程序运行。在获得最近的电子邮件消息对象“MailGetter”之后,Web应用程序将持久存储(通过message.writeTo(FileOutputstream))消息对象,该位置对于“MailFormatter”也是通用的。然后,“MailFormatter”类读取(通过MimeMessage(Session,InputStream)构造函数)并逐个解析消息对象,然后将“XML Content”存储在另一个位置,该位置将由“MobileResponderServlet”读取并发送到移动设备。

Will this process be efficient in real time? Will this be arising problems especially while sharing message objects between "MailGetter" and "MailFormatter" web applications? Please do let me know if there are any other ways. This web application will be handling more than 5000 users (minimum) who have provided numerous email ids for monitoring.

这个过程会实时有效吗?这是否会引起问题,特别是在“MailGetter”和“MailFormatter”Web应用程序之间共享消息对象时?如果还有其他方法,请告诉我。此Web应用程序将处理超过5000个用户(最少),他们提供了大量用于监控的电子邮件ID。

1 个解决方案

#1


I think the only practical thing you can do is put together some test scenario. The above has too many variables to warrant a practical answer relating to performance.

我认为你能做的唯一实际的事情就是把一些测试场景放在一起。上面有太多变数需要保证与性能有关的实际答案。

Put together a source mailbox that has a set of test emails, then knock together some simple mechanism to query this, dump your messages out, and then use your second process to consume. This mechanism would most likely not be your complete solution, but should be representative.

将包含一组测试电子邮件的源邮箱放在一起,然后拼凑一些简单的机制来查询,将您的邮件转储出来,然后使用您的第二个进程来使用。这种机制很可能不是您的完整解决方案,但应具有代表性。

It would be a good idea to make this repeatable and consistent, so as you implement your real solution, you can study whether it's getting slower, and/or benchmark and measure consistently.

将这种可重复性和一致性做好是一个好主意,因此当您实施真正的解决方案时,您可以研究它是否变慢,和/或基准测量和测量。

#1


I think the only practical thing you can do is put together some test scenario. The above has too many variables to warrant a practical answer relating to performance.

我认为你能做的唯一实际的事情就是把一些测试场景放在一起。上面有太多变数需要保证与性能有关的实际答案。

Put together a source mailbox that has a set of test emails, then knock together some simple mechanism to query this, dump your messages out, and then use your second process to consume. This mechanism would most likely not be your complete solution, but should be representative.

将包含一组测试电子邮件的源邮箱放在一起,然后拼凑一些简单的机制来查询,将您的邮件转储出来,然后使用您的第二个进程来使用。这种机制很可能不是您的完整解决方案,但应具有代表性。

It would be a good idea to make this repeatable and consistent, so as you implement your real solution, you can study whether it's getting slower, and/or benchmark and measure consistently.

将这种可重复性和一致性做好是一个好主意,因此当您实施真正的解决方案时,您可以研究它是否变慢,和/或基准测量和测量。