Why got java.lang.OutOfMemoryError: Java heap space

I'm a running an application that to view a thousand of data but I got the below error:
exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:486)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      my.com.elock.admin.servlet.AdminControlServlet.doGet(AdminControlServlet.java:64)
      my.com.elock.admin.servlet.AdminControlServlet.doPost(AdminControlServlet.java:82)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.servlet.ServletException: java.lang.OutOfMemoryError: Java heap space
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
      org.apache.jsp.work.merc_005faudit_005freport_jsp._jspService(merc_005faudit_005freport_jsp.java:3755)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      my.com.elock.admin.servlet.AdminControlServlet.doGet(AdminControlServlet.java:64)
      my.com.elock.admin.servlet.AdminControlServlet.doPost(AdminControlServlet.java:82)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.OutOfMemoryError: Java heap space
sitijaafarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sitijaafarAuthor Commented:
I try to increase the heap size using this command:
java -Xms1024m  -Xmx2048m

But get this error:
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
0
afibarraCommented:
Do your machine has enough memory for that?
0
sitijaafarAuthor Commented:
Ups, not enough I just copy paste from article
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

sitijaafarAuthor Commented:
Finally I can solve it by add this in startup.bat

set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties" -Xms1024m -Xmx1024m -XX:MaxPermSize=128m
0
afibarraCommented:
=)
0
afibarraCommented:
BTW, sorry for my English, it should be:

Does your machine have enough memory for that?
0
a_bCommented:
Instead of increasing the memory size, it might be a better idea to look a the app via a memory profiler ( like yourkit ) to see which object allocations are not being freed by the garbage collector. Even though you have increased the heap size, there is no guarantee of the fact the the exception will not occur again.
0
sitijaafarAuthor Commented:
urmm..how to see which object allocations are not being freed by the garbage collector via memory profiler?
0
a_bCommented:
Have a look at the yourkit demo - http://www.yourkit.com/docs/index.jsp

Download and install yourkit.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sitijaafarAuthor Commented:
I have try to used the yourkit but I'm not able connect to remote application
0
a_bCommented:
What is the issue? Did you look at the demos and tutorials mentioned at the site?
0
sitijaafarAuthor Commented:
yes, I already look at the tutorial.
0
sitijaafarAuthor Commented:
here is the error I got:
error.JPG
0
sitijaafarAuthor Commented:
Good
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.