Java Memory checkMinMemory(long min)

Here you can find the source of checkMinMemory(long min)

Description

Exits with code -1 if maximum memory is below 90% of minimally allowed threshold.

License

Open Source License

Parameter

Parameter Description
min Minimum memory threshold.

Declaration

public static void checkMinMemory(long min) 

Method Source Code

//package com.java2s;
/* /*from   w w  w.j  av a 2  s  .  com*/
 Copyright (C) GridGain Systems. All Rights Reserved.
     
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
    
 http://www.apache.org/licenses/LICENSE-2.0
     
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

public class Main {
    /**
     * Exits with code {@code -1} if maximum memory is below 90% of minimally allowed threshold.
     *
     * @param min Minimum memory threshold.
     */
    public static void checkMinMemory(long min) {
        long maxMem = Runtime.getRuntime().maxMemory();

        if (maxMem < .85 * min) {
            System.err.println("Heap limit is too low (" + (maxMem / (1024 * 1024))
                    + "MB), please increase heap size at least up to " + (min / (1024 * 1024)) + "MB.");

            System.exit(-1);
        }
    }
}

Related

  1. alignMemory(long numBytes)
  2. checkLowMemory()
  3. checkMemory()
  4. compactMemory()
  5. correctMemoryValue(int memory)
  6. displayMemory(String label, long bytes)
  7. dumpMemory()