简体   繁体   中英

java.lang.outofmemory exception jvm heap size insufficient

I tried to read a text file which have only one line. File size is over 50Mb. When I tried to read it using the following code it gives

java.lang.outofmemory exception jvm heap size insufficient

I change the java heap memory to 1GB . But still it gives the same exception.

set JAVA_OPTS=-Xms1024m -Xmx1024m

I use foollowing code pragment to read the file.

BufferedReader Filein1=new BufferedReader(new FileReader( new File( "C:\\ABC\\MsgStream.txt" ))); s=Filein1.readLine();

Can some one please tell me how to overcome this problem. Thanks in advance.

The JAVA_OPTS environment variable is only respected by certain applications (for example the wrapper scripts that are typically used to launch Tomcat). The java command doesn't pay any attention to it.

You need to put the options on the java command line ... before the classname; eg

java -Xms1024m -Xmx1024m ... some.pkg.MainClass ...

(A 1Gb heap should be more than adequate for buffering a 50Mb file.)

Are JAVA_OPTS actually being run in the output? You may need to actually put them on the command line you're running, or include $JAVA_OPTS on it.

It's _JAVA_OPTIONS not JAVA_OPTS

If you have a class like

public class Test {
 public static void main(String args[]) {
   System.out.println("value : " + System.getProperty("foo"));
 }
}

then you should get

> set _JAVA_OPTIONS=-Dfoo=bar
> java Test
> value : bar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM