当前位置: 代码迷 >> Java Web开发 >> 请教这样会造成内存泄漏吗
  详细解决方案

请教这样会造成内存泄漏吗

热度:21   发布时间:2016-04-17 16:12:13.0
请问这样会造成内存泄漏吗?
源码如下:
public   class   SonToXmlServlet   extends   HttpServlet{
/**
  *  
  */
private   static   final   long   serialVersionUID   =   1L;
private   Logger   logger=Logger.getLogger(this.getClass());
public   static   final   String   XML_TOP= " <?xml   version=\ "1.0\ "   encoding=\ "UTF-8\ "?> ";

protected   void   service(HttpServletRequest   req,HttpServletResponse   resp)  
throws   ServletException,java.io.IOException{
try{
String   ParentID   =   RequestUtils.getStringParameter(req, "parentid ", "0 ");
String   action   =   RequestUtils.getStringParameter(req, "action ", " ");
StringBuffer   sb   =   new   StringBuffer( " ");


String   path   =   SonToXmlServlet.class.getResource( "/ ").toString();
path   =   path.substring(0,path.lastIndexOf( "/ "));
path   =   path.substring(0,path.lastIndexOf( "/ "));
logger.debug( "path   is "+path);
ApplicationContext   ctx   =   new   FileSystemXmlApplicationContext(new   String[]   {
path+ "/action-servlet.xml ",
path+ "/applicationContext.xml ",
path+ "/applicationContext-hibernate.xml "
});

sb.append(XML_TOP);
if( "addclass ".equals(action)){
logger.debug( "11 ");
sb.append(this.getTreeByClass(ParentID,3,action,req,resp,ctx));
}else   if( "uclass ".equals(action)){
logger.debug( "uu ");
sb.append(this.getTreeByUserClass(ParentID,3,action,req,resp,ctx));
}
resp.setContentType( "text/xml;charset=UTF-8 ");
resp.getWriter().print(sb.toString());
}catch(Exception   e){
logger.info(e.toString());
}
}

private   StringBuffer   getTreeByClass(String   parentid,
      int   s,
      String   action,
      HttpServletRequest   req,
      HttpServletResponse   resp,
      ApplicationContext   ctx){

StringBuffer   sb   =   new   StringBuffer( " ");
List   l   =   null;
ClassManager   cm   =   (ClassManager)ctx.getBean( "mclassManager ");
l   =   cm.getArticleClass(parentid,0,req,resp);
logger.debug(l.size());
Iterator   it   =   l.iterator();
sb.append( " <tree> ");
while(it.hasNext()){
TArticleclass   t   =   (TArticleclass)it.next();
String   wantAction   =   " ";
switch(s){
case   3:wantAction   =   "javascript:i( 'inid ', ' "+t.getClassnameToQuote()+ " ', ' "+t.getClassid()+ " ', ' "+t.getParentid()+ " ', ' "+t.getChannelid()+ " '); ";break;
}
if(t.getChild()> 0)
sb.append( " <tree   text=\ "   "+t.getClassnameToQuote()+ "\ "   src=\ "sontoxml?parentid= "+t.getClassid()+ "&amp;action= "+action+ "\ "   action=\ " "+wantAction+ "\ "/> ");
else
sb.append( " <tree   text=\ "   "+t.getClassnameToQuote()+ "\ "   action=\ " "+wantAction+ "\ "/> ");
  相关解决方案