OutOfMemoryError: Java heap space MultipartRequest

529 views Asked by At

I have a problem with a MultipartRequest, when I try to upload file. The error is: OutOfMemoryError: Java heap space. I think that the error is in the while cicle, but I don't know what's wrong. Thanks.

This is my code:

InputStream is = part.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];

while ((nRead = is.read(data, 0, data.length)) != -1) {
    buffer.write(data, 0, nRead);
}

buffer.flush();

byte[] out = buffer.toByteArray();

10-Jun-2015 15:39:45.146 SEVERE [http-nio-8080-exec-307] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [tw] created a ThreadLocal with key of type [com.sun.xml.ws.api.client.ServiceInterceptorFactory$1] (value [com.sun.xml.ws.api.client.ServiceInterceptorFactory$1@5901535e]) and a value of type [java.util.HashSet] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Jun-2015 15:39:45.146 SEVERE [http-nio-8080-exec-307] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [tw] created a ThreadLocal with key of type [com.sun.xml.bind.v2.runtime.Coordinator$1] (value [com.sun.xml.bind.v2.runtime.Coordinator$1@1e3025db]) and a value of type [com.sun.xml.bind.v2.runtime.Coordinator[]] (value [[Lcom.sun.xml.bind.v2.runtime.Coordinator;@d9e64e7]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Jun-2015 15:39:57.464 INFO [http-nio-8080-exec-307] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/tw] is completed NOME PART: 1031.zip 10-Jun-2015 15:40:45.772 SEVERE [http-nio-8080-exec-308] null.null caught throwable java.lang.OutOfMemoryError: Java heap space

1

There are 1 answers

0
Bogdan Banciu On

You need to increase your heap space. If you are using eclipse you can check this link and it will show you how to increase the heap size (heap memory is the "place" where all your objects are stored)