The system is out of resources.Consult the following stack trace for details.Java.Lang.OutOfMemory error using java and mysql
I am getting the开发者_运维知识库 following error. The system is out of resources.Consult the stack trace for following details.java.lang.OutOf Memory error using java and mysql.I created 100 tables for my project.I am trying to insert the values that are generated randomly by using the concept of random numbers i am able to update the values in 25 tables rather than 100 tables.Please help me resolve the error.Thanks a lot
An OutOfMemory error means that you are allocating more memory than your JVM allows. The first thing to do would be to increase the max heap size by passing the following argument to java
:
-Xmx1024m
This will increase your heap size to 1GB, rather than the default 64MB. Adjust as you like.
You will also want to make sure your code has no memory leaks. Memory leaks occur when you hold references to objects that you no longer need.
Something fishy is going on.
Normally, when an OutOfMemoryError
occurs while our application is running, the message reads as follows:
Exception in thread "main" java.lang.OutOfMemoryError
at com.acme.GreatestProgramEver.main(Program.java:19)
Specifically, there is no message that reads "The system is out of resources. Consult the following stack trace for details" unless we catch the exception and report it ourselves, making sure to output such a message, proper English and all. And I suspect the OP is not doing such a thing.
However, I have seen the java compiler display precisely that message when it runs out of memory.
This leads me to suspect that there is a tiny little detail that the OP forgot to mention:
This error is not happening during runtime.
This error is happening during compilation.
So, your compiler needs more memory.
If you are using IntelliJ IDEA:
Increasing the amount of memory available to IntelliJ IDEA by specifying a higher number for -Xmx
in bin\idea64.exe.vmoptions
will only help the internal compiler of the IDE with parsing your source files as you type in order to show you errors in the editor.
In order to increase the amount of memory available when actually building, you need to open up "Options", go to "Build, Execution, Deployment" -> "Compiler", and specify a large number in "Build process heap size (Mbytes):"
2000
should do it even for a large project.
Note: all answers mentioning memory leaks are wrong, because this issue has to do with the compiler, not your code. At the time that the compiler is compiling your code, your code hardly exists yet, much less has it had a chance to run, let alone allocate any memory. So, your leaky code is irrelevant.
You can increase the size of the heap for your Java process from the commandline. try adding -Xmx512m
to your commandline args.
It could be because of the memory leak. Ensuring bellow actions are done could avoid memory leak.
1 . All the statements and connections are closed after the use
2 . All the streams created are closed after use.
3 . All the close operations are done inside the finally block.
I cannot mention all the causes of memory leak . May be the above points could help you.
精彩评论