我正在从 hadoop 命令运行 java 类 test.java:
$ hadoop test
我正在使用 stringBuilder,它的大小正在耗尽内存:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder. java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572 )
at java.lang.StringBuffer.append(StringBuffer.java:320)
at java.io.StringWriter.write(StringWriter.java:60)
at org.json.JSONObject.quote(JSONObject.java:1287)
at org.json.JSONObject.writeValue(JSONObject.java:1597)
at org.json.JSONObject.write(JSONObject.java:1649)
at org.json.JSONObject.writeValue(JSONObject.java:1574)
at org.json.JSONArray.write(JSONArray.java:929)
at org.json.JSONObject.writeValue(JSONObject.java:1576)
at org.json.JSONObject.write(JSONObject.java:1649)
at org.json.JSONObject.writeValue(JSONObject.java:1574)
at org.json.JSONObject.write(JSONObject.java:1632)
at org.json.JSONObject.toString(JSONObject.java:1443)
我知道在java中我们可以通过提供堆空间大小来运行java程序:
java -Xmx4G test
如果我像这样运行它,我该如何在使用 hadoop 运行时做到这一点:
$ hadoop -Xmx4G test
它抛出异常:
Caused by: java.lang.ClassNotFoundException: java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: java. Program will exit.
Error: No command named `-Xmx4g' was found. Perhaps you meant `hadoop Xmx4g'
我想永久更改堆大小。