系统资源不足。详情查看下面的堆栈跟踪。Java.Lang.OutOfMemory 使用java和mysql的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2242037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:16:39  来源:igfitidea点击:

The system is out of resources.Consult the following stack trace for details.Java.Lang.OutOfMemory error using java and mysql

java

提问by S.PRATHIBA

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

我收到以下错误。系统资源不足。请查阅堆栈跟踪以了解以下详细信息。java.lang.OutOf Memory 错误使用 java 和 mysql。我为我的项目创建了 100 个表。我试图插入使用概念随机生成的值随机数我能够更新 25 个表而不是 100 个表中的值。请帮我解决错误。非常感谢

回答by danben

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:

OutOfMemory 错误意味着您分配的内存超出了 JVM 允许的范围。首先要做的是通过将以下参数传递给 来增加最大堆大小java

-Xmx1024m

-Xmx1024m

This will increase your heap size to 1GB, rather than the default 64MB. Adjust as you like.

这会将您的堆大小增加到 1GB,而不是默认的 64MB。随心所欲地调整。

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.

您还需要确保您的代码没有内存泄漏。当您持有对不再需要的对象的引用时,就会发生内存泄漏。

回答by Mike Nakis

Something fishy is going on.

正在发生一些可疑的事情。

Normally, when an OutOfMemoryErroroccurs while our application is running, the message reads as follows:

通常,当OutOfMemoryError我们的应用程序运行时发生 ,消息如下所示:

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.

具体来说,除非我们捕获异常并自己报告,否则不会出现“系统资源不足。请参阅以下堆栈跟踪以获取详细信息”的消息,确保输出这样的消息,正确的英文等等。而且我怀疑 OP 没有做这样的事情。

However, I have seen the java compiler display precisely that message when it runs out of memory.

但是,我已经看到 java 编译器在内存不足时准确显示该消息。

This leads me to suspect that there is a tiny little detail that the OP forgot to mention:

这让我怀疑 OP 忘记提及一个很小的细节:

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:

如果您使用的是 IntelliJ IDEA:

Increasing the amount of memory available to IntelliJ IDEA by specifying a higher number for -Xmxin bin\idea64.exe.vmoptionswill 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.

通过为-Xmxin指定更高的数字来增加 IntelliJ IDEA 可用的内存量bin\idea64.exe.vmoptions只会帮助 IDE 的内部编译器在您键入时解析源文件,以便在编辑器中显示错误。

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):"

为了增加实际构建时可用的内存量,需要打开“Options”,进入“Build, Execution, Deployment”->“Compiler”,在“Build process heap size (Mbytes)”中指定一个大的数字):"

2000should do it even for a large project.

2000即使是大型项目也应该这样做。

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.

注意:所有提到内存泄漏的答案都是错误的,因为这个问题与编译器有关,与您的代码无关。在编译器编译您的代码时,您的代码几乎不存在,更不用说它有机会运行了,更不用说分配任何内存了。因此,您的泄漏代码无关紧要。

回答by akf

You can increase the size of the heap for your Java process from the commandline. try adding -Xmx512mto your commandline args.

您可以从命令行增加 Java 进程的堆大小。尝试添加-Xmx512m到您的命令行参数。

回答by Sreejesh

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.

我不能提及内存泄漏的所有原因。可能以上几点可以帮到你。