Java AtomicLong Accumulator calculateMemory()

Here you can find the source of calculateMemory()

Description

calculate Memory

License

Open Source License

Declaration

public static int calculateMemory() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.atomic.AtomicBoolean;

public class Main {
    private static AtomicBoolean memory = new AtomicBoolean(false);

    public static int calculateMemory() {
        long heapSize = Runtime.getRuntime().totalMemory();
        long heapMaxSize = Runtime.getRuntime().maxMemory();
        if (heapSize < heapMaxSize) {
            return Integer.MAX_VALUE;
        }//from w  w  w.  ja va2  s.c  om
        long heapFreeSize = Runtime.getRuntime().freeMemory();
        int size = (int) ((heapFreeSize * 100) / heapMaxSize);
        if (size > (100 - 95)) {
            memoryPlentifulTask();
            return Integer.MAX_VALUE;
        }
        return size;
    }

    public static void memoryPlentifulTask() {
        memory.set(false);
    }
}

Related

  1. addInlineCollectionToSqlString(StringBuilder sql, Collection values)
  2. getDefaultSSLProtocol()
  3. getEnabledSSLProtocols()
  4. getIncrement()
  5. min(List list)