当前位置:编程学习 > JAVA >>

关于绿色版Tomcat6服务器下设置JRE的default VM Arguments值的问题

我目前出现的一个情况是:
    开发环境使用的是MyEclipse8.5,Tomcat6绿色版和JRE6,上传附件存储到数据库中,上传2MB左右的附件都没问题,但当上传8MB的附件时,发现总会报java.lang.OutOfMemoryError: Java heap space,随即在MyEclipse->Java->Installed JREs下设置JRE6的Default VM Arguments的值为:-Xms128m -Xmx512m,此时8MB的附件可以上传成功了。

    但如果我将项目用这个Tomcat6绿色版和JRE6发布后,想请教一下在哪配置上述中设置的JRE6的Default VM Arguments值?

    我在Tomcat6/bin下的catalina.bat中设置过JAVA_OPTS的值,但还是在上传8MB文件时会抛出异常? tomcat java myeclipse 服务器 --------------------编程问答-------------------- 上传个附件都内存溢出?去检查下你的代码吧 --------------------编程问答--------------------
引用 1 楼 whycodewhy 的回复:
上传个附件都内存溢出?去检查下你的代码吧


代码没有问题,确实在修改了JRE的Default VM Arguments为-Xms128m -Xmx512m后,就上传成功了。  --------------------编程问答--------------------
引用 2 楼 woshihw 的回复:
引用 1 楼 whycodewhy 的回复:上传个附件都内存溢出?去检查下你的代码吧

代码没有问题,确实在修改了JRE的Default VM Arguments为-Xms128m -Xmx512m后,就上传成功了。


java.lang.OutOfMemoryError: Java heap space是在将文件插入到数据库时的那一步报的错

我想知道将项目用这个Tomcat6绿色版和JRE6发布后,在哪个配置文件中可以设置JRE6的Default VM Arguments值? --------------------编程问答--------------------
望高手指点! --------------------编程问答-------------------- 贴源码出来看看 --------------------编程问答-------------------- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="java.io.File"%>
<%@page import="org.apache.commons.fileupload.FileUploadException"%>
<%@page import="java.util.List"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="java.util.Iterator"%>
<%@page import="org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="edu.jinjiao.fg.tools.storeFileToMySQL"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="edu.jinjiao.fg.service.IFgService"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="edu.jinjiao.fg.n.entity.softupdate"%>
<%@page import="java.io.ByteArrayOutputStream"%>
<%@page import="java.io.FileInputStream"%>

<%
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IFgService svc = (IFgService)wac.getBean("FgService");

String returnStr = "[{msage:'false'}]";
response.setCharacterEncoding("UTF-8");
final long MAX_SIZE= 50 * 1024 * 1024; 
String fileFolder = this.getServletContext().getRealPath("/soft");
//判断该请求是否是文件上传的请求  
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    try{
    if(isMultipart){
     DiskFileItemFactory factory = new DiskFileItemFactory();
     //设置上传文件时用于临时存放文件的内存大小  
        factory.setSizeThreshold(10 * 1024); 
        //设置存放临时文件的目录  
        factory.setRepository(new File(fileFolder+"/temp"));
        ServletFileUpload upload = new ServletFileUpload(factory);
        //设置最大上传尺寸  
        upload.setSizeMax(MAX_SIZE);
        try { 
             List<FileItem> filelist = upload.parseRequest(request);
             for(Iterator<FileItem> it = filelist.iterator(); it.hasNext() ; ){
                 FileItem item = it.next();  
                 //判断是form表单域还是上传文件file域  
                 if(item.isFormField()){
                     //处理form表单域  
                     String name = item.getFieldName();  
                     String value = item.getString();  
                 }else{  
                     //处理fileUpload  
                     //得到表单域的名称  
                     String fieldName = item.getFieldName();  
                     //取得文件类型  
                     String contentType = item.getContentType();  
                     //文件的全路径  
                     String fileName = item.getName();
                     //得到去除路径的文件名  
                     int index = fileName.lastIndexOf("\\");  
                     fileName = fileName.substring(index+1);
                     boolean typeTag = false;
                     if(fileName.indexOf("exe")>-1 || fileName.indexOf("msi")>-1){
                      if(fileName.split("\\.").length>0){
                      if("exe".equalsIgnoreCase(fileName.split("\\.")[fileName.split("\\.").length-1])){
                      typeTag = true;
                      }
                      if("msi".equalsIgnoreCase(fileName.split("\\.")[fileName.split("\\.").length-1])){
                      typeTag = true;
                      }
                      }
                     }
                     if(typeTag){
                      //构建一个文件  
                     File uploadFile = new File(fileFolder ,fileName);
                     //保存文件  
                     System.out.println("-------存储文件开始--------");
                     item.write(uploadFile);
                     System.out.println("-------存储文件结束--------");
                     String fileSize = "";
                     DecimalFormat df = new DecimalFormat("#.00");
                     if(item.getSize()<1024){
                      fileSize = item.getSize()+"字节";
                     }else if(item.getSize()>=1024 && item.getSize()<1024*1024){
                      fileSize = df.format(item.getSize()/Double.valueOf(1024))+"KB";
                     }else if(item.getSize()>=1024*1024){
                      fileSize = df.format(item.getSize()/Double.valueOf(1024*1024))+"MB";
                     }
                     Date date = new Date();
                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
                     //往数据库中添加数据
                     ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); //转换byte数组  
 FileInputStream in = new FileInputStream(new File(fileFolder ,fileName)); //文件  
 int ch;  
 //转换成byte数组  
 while ((ch = in.read()) != -1) {  
  bytestream.write(ch);  
 }  
 byte imgdata[] = bytestream.toByteArray();
                     softupdate su = new softupdate();
                     su.setFilename(fileName);
                     su.setFilesize(fileSize);
                     su.setUpdatetime(date);
                     su.setSoftpage(imgdata);
                     su.setTag(1);
                     System.out.println("存储文件的长度------>"+su.getSoftpage().length);
                     //开始存储软件start~~~~~~~~~~~~~~~~~
                     svc.delSoftByTag(1);//先删除已存在的软件
                     System.out.println("------------将文件存储到数据库Start-----------");
                     svc.saveTaskSvcSoft(su);
                     System.out.println("------------将文件存储到数据库End------------");
                     //开始存储软件end~~~~~~~~~~~~~~~~~~~
                     returnStr = "[{msage:'true',fileSize:'"+fileSize+"',fileName:'"+fileName+"',updateTime:'"+sdf.format(date)+"'}]";
                       uploadFile.delete();
                     }else{
                      returnStr = "[{msage:'typeWrong'}]";
                     }
                 }
             }
         } catch (FileUploadException e) {
          e.printStackTrace();
             if(e instanceof SizeLimitExceededException ){  
                returnStr = "[{msage:'big'}]";
             }  
         } catch (Exception e) {
          e.printStackTrace();
            returnStr = "[{msage:'false'}]";
         }
    }else{
     System.out.println("asdfasdfasdfasdf");
     returnStr = "[{msage:'false'}]";
    }
    }catch(Exception e){
     e.printStackTrace();
     returnStr = "[{msage:'false'}]";
    }
System.out.println(returnStr);
JSONArray json = JSONArray.fromObject(returnStr);
response.getWriter().write(json.toString());
response.getWriter().flush();
%> --------------------编程问答--------------------
引用 5 楼 whycodewhy 的回复:
贴源码出来看看


这是上传文件的地方,总在svc.saveTaskSvcSoft(su);这个地方报错的! --------------------编程问答--------------------
引用 7 楼 woshihw 的回复:
引用 5 楼 whycodewhy 的回复:贴源码出来看看

这是上传文件的地方,总在svc.saveTaskSvcSoft(su);这个地方报错的!

上传完把文件写入流关闭,imgdata这个对象插入完后,赋值为null,另外你把文件存数据库干嘛
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,