web应用程序仍然在处理尚未完成的请求

应用程序第一次运行正常,第二次运行后出现以下错误,重启之后运行第一次没问题,第二次又出现问题了。请问是什么原因呢?

警告: The web application [jConnect] is still processing a request that has yet to finish. This is very likely to create a memory leak. You can control the time allowed for requests to finish by using the unloadDelay attribute of the standard Context implementation. Stack trace of request processing thread:

java.net.SocketInputStream.socketRead0(Native Method)

java.net.SocketInputStream.read(Unknown Source)

java.net.SocketInputStream.read(Unknown Source)

java.net.SocketInputStream.read(Unknown Source)

org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:213)

org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:180)

org.rosuda.REngine.Rserve.protocol.RTalk.request(RTalk.java:250)

org.rosuda.REngine.Rserve.RConnection.eval(RConnection.java:231)

com.main.service.Execute.getRobj(Execute.java:54)

com.main.web.ExecuteR.doGet(ExecuteR.java:41)

com.main.web.ExecuteR.doPost(ExecuteR.java:55)

javax.servlet.http.HttpServlet.service(HttpServlet.java:648)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)

org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)

org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)

org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)

org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)

org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)

org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)

java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

java.lang.Thread.run(Unknown Source)

下面是我的代码:

1.servlet类

package com.main.web;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.rosuda.REngine.REXP;

import org.rosuda.REngine.Rserve.RConnection;

import org.rosuda.REngine.Rserve.RserveException;

import com.main.service.Execute;

import com.main.util.Rservel;

/**

* Servlet implementation class ExecuteR

*/

@WebServlet("/ExecuteR")

public class ExecuteR extends HttpServlet {

private static final long serialVersionUID = 1L;

/**

* @see HttpServlet#HttpServlet()

*/

public ExecuteR() {

super();

// TODO Auto-generated constructor stub

}

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String RSentences=request.getParameter("data");//这个例子必须到页面点击

//System.out.println(RSentences);

Execute wc=new Execute();

REXP xp;

try {

xp = wc.getRobj(RSentences);//获得R对象

wc.createPlot(xp,wc);//

} catch (Exception e) {

e.printStackTrace();

}

}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

doGet(request, response);

}

}

2.com.main.service.Execute类

package com.main.service;

import java.awt.Graphics;

import java.awt.GraphicsConfiguration;

import java.awt.GraphicsDevice;

import java.awt.GraphicsEnvironment;

import java.awt.HeadlessException;

import java.awt.Image;

import java.awt.MediaTracker;

import java.awt.Toolkit;

import java.awt.Transparency;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import org.rosuda.REngine.REXP;

import org.rosuda.REngine.Rserve.RConnection;

import com.main.util.Rservel;

public class Execute extends JFrame{

private static final long serialVersionUID=1L;

static Image img;

public static REXP getRobj(String RSentences) throws Exception{

RConnection c=Rservel.getRConnection();

c.setStringEncoding("utf8");//设置字符编码

//返回R的版本

REXP Rservesion=c.eval("R.version.string");

System.out.println("12:"+Rservesion.asString());

String [] arr = RSentences.split("\\s+");

for(String RSentence : arr){

System.out.println("done");

}

REXP xp=c.parseAndEval("jpeg('test.jpg',quality=90)");

c.eval("install.packages('RColorBrewer')");

c.eval("library(RColorBrewer)");

c.eval("H <- c(7,12,28,3,41)");

c.eval("colors<-brewer.pal(5,'Set1')");

c.parseAndEval(" barplot(H,rep(1,5),col=colors);dev.off()");

xp=c.parseAndEval("r=readBin('test.jpg','raw',3000*3000);unlink('test.jpg');r");

c.close();

return xp;

}

public void createPlot(REXP xp, JFrame f)throws Exception{

Image image=Toolkit.getDefaultToolkit().createImage(xp.asBytes());

BufferedImage bufferedImage=toBufferedImage(image);

try {

ImageIO.write(bufferedImage, "JPG", new File("./outImg/98.jpg"));

} catch (IOException e) {

e.printStackTrace();

}

}

public BufferedImage toBufferedImage(Image image) {

if (image instanceof BufferedImage) {

return (BufferedImage)image;

}

image = new ImageIcon(image).getImage();

BufferedImage bimage = null;

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

try {

int transparency = Transparency.OPAQUE;

GraphicsDevice gs = ge.getDefaultScreenDevice();

GraphicsConfiguration gc = gs.getDefaultConfiguration();

bimage = gc.createCompatibleImage(

image.getWidth(null), image.getHeight(null), transparency);

} catch (HeadlessException e) {

}

if (bimage == null) {

int type = BufferedImage.TYPE_INT_RGB;

bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);

}

Graphics g = bimage.createGraphics();

g.drawImage(image, 0, 0, null);

g.dispose();

return bimage;

}

}

回答:

这个什么鬼?问题估计处在这里,需要关闭这个资源。可问题是你从哪里冒出这个ImageIO的?

以上是 web应用程序仍然在处理尚未完成的请求 的全部内容, 来源链接: utcz.com/p/176063.html

回到顶部