Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javamail IMAP中getMessages和GetMessagesById的内存使用差异_Java_Memory_Imap_Fetch_Uid - Fatal编程技术网

javamail IMAP中getMessages和GetMessagesById的内存使用差异

javamail IMAP中getMessages和GetMessagesById的内存使用差异,java,memory,imap,fetch,uid,Java,Memory,Imap,Fetch,Uid,我使用java邮件api从IMAP文件夹获取消息。我们有一个包含1000条消息的文件夹。假设第一条消息的UID2000,最后一条消息的UID8000 当我们对所有消息执行get时: //call 1 // use indices, get the range 1-1000 Message m1[] = folder.getMessages(1, 1000); 消耗很少的内存,但另一方面 //call 1 // use the first UID and last UID in the fold

我使用java邮件api从IMAP文件夹获取消息。我们有一个包含1000条消息的文件夹。假设第一条消息的UID2000,最后一条消息的UID8000

当我们对所有消息执行get时:

//call 1
// use indices, get the range 1-1000
Message m1[] = folder.getMessages(1, 1000);
消耗很少的内存,但另一方面

//call 1
// use the first UID and last UID in the folder
Message m2[] = folder.getMessagesByUID(2000, 8000);
使用探查器分析时会消耗大量内存


返回的数组大小相同,两个数组(消息模板)的成员完全相同。但是我无法解释调用2消耗大量内存的原因?

您能为我们量化内存差异吗?如果我们查看探查器(例如,您的工具包,您会看到数十mb的差异。但它认为我找到了原因,当查看IMAPFolder的源代码时,当调用getByUid时,消息也会被放入类范围哈希表中(uidtable),如果处理10.000条消息,差异会增大。另一方面,getMessages仅从messagecache中拾取。我希望获取自上次处理uid以来的所有消息,例如f.getMessagedByUid(lastStored,uid.MAX),但如果文件夹包含一百万封邮件,并且lastStored对应于一封非常旧的邮件,则调用会消耗太多内存。我认为最好获取上次处理邮件的messagenumber,然后调用getMessages(msgnumberoflastprocessed,numallmessages),假设我们需要uid 1000之后的邮件。选项1:f.GetMessagesById(1000,UIDMAX).option2:msgnum=f.getMessageByUID(1000).getMessageNumber();f.getMessages(msgnum,allmessagecount)