简体   繁体   中英

Setting JVM arguments at runtime

I keep getting the following error when I run my program:

java.lang.OutOfMemoryError : Java heap space

I tried fixing this by adding -Xms512M -Xmx1524M to both Program arguments and VM arguments (I use eclipse), but this doesn't seem to prevent the error.

If the solution is adding more memory in eclipse run configuration, the question is > is this going to be exported too? or is it just for me, how can I make sure this doesn't happen on other computers?

Current code

 private static void checkSumGen() throws IOException NoSuchAlgorithmException
    {

    File plFolder = new File(".\\Plugins");
    File[] listOfFiles = plFolder.listFiles();
    List<String> listClone = new ArrayList<String>();
    for (int i = 0; i < listOfFiles.length; i++)
        {
            File file = listOfFiles[i];
            String fileloc = file.getAbsolutePath();
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            FileInputStream fis = new FileInputStream(fileloc);

            byte[] dataBytes = new byte[1024];

            int nread = 0;
            while ((nread = fis.read(dataBytes)) != -1)
            {
                md.update(dataBytes, 0, nread);
            } ;
            byte[] mdbytes = md.digest();

            // convert the byte to hex format method 1
            StringBuffer sb = new StringBuffer();
            for (int i1 = 0; i1 < mdbytes.length; i++)
                {
                    sb.append(Integer.toString((mdbytes[i1] & 0xff) + 0x100, 16).substring(1)); 
                }

            System.out.println("Hex format : " + sb.toString());

            // convert the byte to hex format method 2
            StringBuffer hexString = new StringBuffer();
            for (int i2 = 0; i2 < mdbytes.length; i++)
                {
                    hexString.append(Integer.toHexString(0xFF & mdbytes[i2]));
                }
            System.out.println("Hex format : " + hexString.toString());
        }

}

You have an infinite loop in your code that causes the OutOfMemoryError .

In:

for (int i1 = 0; i1 < mdbytes.length; i++)

you increment i instead of i1 causing i1 < mdbytes.length to be true forever.

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