java上传文件时tomcat崩溃
在项目中,我用到的tomcat是5.5的,在linux上跑。最近发现在上传文件时,如果连续上传10个左右,就会出现tomcat崩溃的情况。JVM的内存我已经设置成为512M的了。现将代码分别贴出,请各位看一看:(是SSH架构的)jsp:
<form action="tArenamessage.do" name="tArenamemessageForm" id="tArenamemessageForm" method="POST"enctype="multipart/form-data" >
...
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
....
/form>
===============================
struts.xml:
<form-bean name="TArenamemessageForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="name"type="java.lang.String" />
...
<form-property name="file1"type="org.apache.struts.upload.FormFile" />
<form-property name="file2"type="org.apache.struts.upload.FormFile" />
<form-property name="file3"type="org.apache.struts.upload.FormFile" />
</form>
<!-- 场馆管理模块 -->
<action path="/tArenamessage"scope="request" type="org.springframework.web.struts.DelegatingActionProxy" validate="false" name="TArenamemessageForm">
<forward name="service" path="/../WEB-INF/jsp/admin/jsp/tArenamessage.jsp"> </forward>
</action>
====================================
aciton:
//保存
public boolean setBeanValueByDynaActionForm(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
this.myExecute(mapping, form, request, response);
DynaActionForm hzForm = (DynaActionForm) form;
...
FormFile localfile = null;
//外景照片
localfile = (FormFile)hzForm.get("file1");
if(localfile!=null) {this.upload(localfile, request, 6L);}
localfile = (FormFile)hzForm.get("file2");
if(localfile!=null) {this.upload(localfile, request, 6L);}
localfile = (FormFile)hzForm.get("file3");
if(localfile!=null) {this.upload(localfile, request, 6L);}
...
}
//上传文件
private void upload(FormFile localfile,HttpServletRequest request,long flag){
String finalFileName="";
if(localfile!=null) {
finalFileName = Upload.uploadAttachment( localfile , request);//上传文件
}
if(finalFileName != null && !finalFileName.equals("")){
uploadFile(localfile,request,finalFileName,flag);//保存到附件表
}
}
上传文件的类:
public class Upload {
public static String uploadAttachment( FormFile file , HttpServletRequest request){
if( SystemGlobal.uploadAccess.toString().indexOf(file.getContentType())>=0 && file.getFileSize() <= ( 2048 * (Integer.parseInt( SystemGlobal.uploadAccess.toString()) ))){ //是图片并且小于?k
String path = SystemGlobal.webDir(request) + SystemGlobal.uploadAccess +System.getProperty("file.separator") + StringUtil.date2String() +System.getProperty("file.separator");
File dir = new File(path);
if(!dir.exists()){dir.mkdir();}
String filename = "";
if(!file.getFileName().equals("")){
try{
filename = StringUtil.time2String() + StringUtil.ramdom(4)+ "." + file.getFileName().substring(file.getFileName().length()-3) ;
InputStream stream = file.getInputStream();
FileOutputStream output = new FileOutputStream( path + filename );
int len = -1;
byte[] buf = new byte;
while((len = stream.read(buf)) != -1){
output.write(buf,0,len);
}
output.close();
stream.close();
}catch(IOException e){Log.error( Upload.class , "upload write stream ha error:" + e);}
}
return filename;
}
return "";
}
==============================
tareamanage.hbm.xml一对多,一个场馆可以有多个图片
<set name="TUploadfiles" inverse="false" cascade="save-update" fetch="subselect" lazy="false">
<cache usage="read-write"/>
<key>
<column name="OBJID" length="50" />
</key>
<one-to-many class="com.webaorta.comm.pojo.TUploadfile" />
</set>
====================================
大致上就是这些了,代码里是否存在不合理的地方而导致什么原因从而令到tomcat死掉了呢?tomcat里的logs也没有一点报错的信息可以看的。
后来我直接将其转换为open session in view模式,奇怪的是我在windows下可以运行(开发机),但在linux下就报session已经关闭这个错误的了。这又是为什么呢?(服务器是linux系统).
请各位看一看吧,如果搞不好这个可能会丢饭碗的。谢谢大家了。
页:
[1]