这个类是获取邮件所有信息的,包括附件信息。获得到50条的时候还可以。超过60条邮件的时候,就会报
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
请问各位朋友,帮我分析怎么回事?谢谢!~ 急!!!
public ContentModel getMailInfo(UseConfigModel model, String entityId, String categoryId,Folder folder) throws Exception {
ContentModel content = new ContentModel();
try {
Message msg = null;
if(folder==null)
getFolder(model, "1", "9999/4");
msg = folder.getMessage(Integer.parseInt(entityId));
if (msg != null) {
List list = new ArrayList();
List<AttachmentModel> attachList = new ArrayList();
Address[] address = msg.getFrom();
String from = "";
for (int i = 0; i < address.length; i++) {
from = FrameworkUtil.convertToNull(getDisplayAddress(address[i]));
}
int start = from.indexOf("<");
int end = from.indexOf(">");
if (start > -1 && end > 0 && end > start) {
from = FrameworkUtil.convertToNull(from.substring(start + 1, end)).trim();
}
String title = "无主题";
Date date = msg.getSentDate();
if(date==null)date = new Date();
String strMailSubject[] = msg.getHeader("Subject");
if (strMailSubject != null) {
if (strMailSubject[0] != null && !strMailSubject[0].equals("")) {
title = strMailSubject[0];
title=new String(title.getBytes("iso8859-1"),"gb2312");//最后加上的改正编码的代码
title = MimeUtility.decodeText(title);
}
}
if (msg.isMimeType("text/*")) {
list.add(new ContentItemModel("标题:", title));
list.add(new ContentItemModel("来自:", from));
list.add(new ContentItemModel("发送日期:", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)));
list.add(new ContentItemModel("正文:", FrameworkUtil.claerHTML(FrameworkUtil.convertToNull("" + msg.getContent()))));
list.add(new ContentItemModel("sender:", from + ";" + FrameworkUtil.convertToNull(msg.getSubject())));
} else if (msg.isMimeType("multipart/*")) {
list.add(new ContentItemModel("标题:", title));
list.add(new ContentItemModel("来自:", from));
list.add(new ContentItemModel("发送日期:", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)));
list.add(new ContentItemModel("sender:", from + ";" + FrameworkUtil.convertToNull(null == msg.getSubject() || msg.getSubject().equals("") ? "无主题" : msg.getSubject())));
//附件
if (msg.getContent() instanceof Multipart) {
Multipart mp = (Multipart) msg.getContent();
String type = getContentType(mp);
boolean addflalg = true;
for (int t = 0; t < mp.getCount(); t++) {
BodyPart part = mp.getBodyPart(t);
String fileName = part.getFileName();
String sct = part.getContentType();
String disposition = part.getDisposition();
if (disposition != null && disposition.equals(Part.ATTACHMENT)) {
fileName = MimeUtility.decodeText(fileName);
AttachmentModel attach = new AttachmentModel();
attach.setName(fileName);
attach.setLink("" + t);
int begin = fileName.lastIndexOf(".");
String ftype = "";
if (begin > -1) {
ftype = fileName.substring(begin, fileName.length()).toLowerCase();
if (ftype.equals(".doc") || ftype.equals(".txt")) {
attach.setType("open");
}
}
attachList.add(attach);
} else {
String mcontent = getPart(part, t, 2);
//System.out.println(mcontent+"==");
mcontent = FrameworkUtil.claerHTML(mcontent);
// System.out.println(mcontent+"XXXX");
if (!FrameworkUtil.convertToNull(mcontent).equals("")) {
if (addflalg) {
list.add(new ContentItemModel("正文:", FrameworkUtil.claerHTML(mcontent)));
}
if (type.equals("1")) {
addflalg = false;
}
}
}
} }
}
content.setContentItems(list);
content.setAttachmentList(attachList);
}
} catch (Exception e) {
throw e;
} finally {
store.close();
folder.close(false);
}
return content;
}
这个类是获取邮件所有信息的,包括附件信息。获得到50条的时候还可以。超过60条邮件的时候,就会报
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
请问各位朋友,帮我分析怎么回事?谢谢!~ 急!!!
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
请问各位朋友,帮我分析怎么回事?谢谢!~ 急!!!
public ContentModel getMailInfo(UseConfigModel model, String entityId, String categoryId,Folder folder) throws Exception {
ContentModel content = new ContentModel();
try {
Message msg = null;
if(folder==null)
getFolder(model, "1", "9999/4");
msg = folder.getMessage(Integer.parseInt(entityId));
if (msg != null) {
List list = new ArrayList();
List<AttachmentModel> attachList = new ArrayList();
Address[] address = msg.getFrom();
String from = "";
for (int i = 0; i < address.length; i++) {
from = FrameworkUtil.convertToNull(getDisplayAddress(address[i]));
}
int start = from.indexOf("<");
int end = from.indexOf(">");
if (start > -1 && end > 0 && end > start) {
from = FrameworkUtil.convertToNull(from.substring(start + 1, end)).trim();
}
String title = "无主题";
Date date = msg.getSentDate();
if(date==null)date = new Date();
String strMailSubject[] = msg.getHeader("Subject");
if (strMailSubject != null) {
if (strMailSubject[0] != null && !strMailSubject[0].equals("")) {
title = strMailSubject[0];
title=new String(title.getBytes("iso8859-1"),"gb2312");//最后加上的改正编码的代码
title = MimeUtility.decodeText(title);
}
}
if (msg.isMimeType("text/*")) {
list.add(new ContentItemModel("标题:", title));
list.add(new ContentItemModel("来自:", from));
list.add(new ContentItemModel("发送日期:", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)));
list.add(new ContentItemModel("正文:", FrameworkUtil.claerHTML(FrameworkUtil.convertToNull("" + msg.getContent()))));
list.add(new ContentItemModel("sender:", from + ";" + FrameworkUtil.convertToNull(msg.getSubject())));
} else if (msg.isMimeType("multipart/*")) {
list.add(new ContentItemModel("标题:", title));
list.add(new ContentItemModel("来自:", from));
list.add(new ContentItemModel("发送日期:", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)));
list.add(new ContentItemModel("sender:", from + ";" + FrameworkUtil.convertToNull(null == msg.getSubject() || msg.getSubject().equals("") ? "无主题" : msg.getSubject())));
//附件
if (msg.getContent() instanceof Multipart) {
Multipart mp = (Multipart) msg.getContent();
String type = getContentType(mp);
boolean addflalg = true;
for (int t = 0; t < mp.getCount(); t++) {
BodyPart part = mp.getBodyPart(t);
String fileName = part.getFileName();
String sct = part.getContentType();
String disposition = part.getDisposition();
if (disposition != null && disposition.equals(Part.ATTACHMENT)) {
fileName = MimeUtility.decodeText(fileName);
AttachmentModel attach = new AttachmentModel();
attach.setName(fileName);
attach.setLink("" + t);
int begin = fileName.lastIndexOf(".");
String ftype = "";
if (begin > -1) {
ftype = fileName.substring(begin, fileName.length()).toLowerCase();
if (ftype.equals(".doc") || ftype.equals(".txt")) {
attach.setType("open");
}
}
attachList.add(attach);
} else {
String mcontent = getPart(part, t, 2);
//System.out.println(mcontent+"==");
mcontent = FrameworkUtil.claerHTML(mcontent);
// System.out.println(mcontent+"XXXX");
if (!FrameworkUtil.convertToNull(mcontent).equals("")) {
if (addflalg) {
list.add(new ContentItemModel("正文:", FrameworkUtil.claerHTML(mcontent)));
}
if (type.equals("1")) {
addflalg = false;
}
}
}
} }
}
content.setContentItems(list);
content.setAttachmentList(attachList);
}
} catch (Exception e) {
throw e;
} finally {
store.close();
folder.close(false);
}
return content;
}
这个类是获取邮件所有信息的,包括附件信息。获得到50条的时候还可以。超过60条邮件的时候,就会报
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
请问各位朋友,帮我分析怎么回事?谢谢!~ 急!!!
解决方案 »
- spring+hibernate整合问题
- 不显示删除回复显示所有回复显示星级回复显示得分回复 struts2 验证码报错 org.apache.catalina.core.StandardWrappe
- 请教服务器内存溢出问题
- 推荐初学者学习Java的路线
- 有个问题真是郁闷!--关于java类的编译问题
- 中文URL的问题,谢谢了。
- 统计一下,大家面试 java jsp软件开发时候的题目,有没有十分变态的???
- need advice 100score
- 有人在tomcat4.1.24下配置过apache soap2.3吗? 请进来看一下我的问题
- j2ee中的jdbc
- spring框架问题
- java socket通讯心跳数据包采用定长包头,长度为8
dyllove98
请问你说的临时对象指的什么?能说的更具体些吗?!
只是增加-Xmx也不是解决问题的办法
我的解决办法是当接收的邮件的字节数达到一定内后,就重新创建Session,重新登录,这样byte[]就会释放了