Example usage for java.lang Runtime freeMemory

List of usage examples for java.lang Runtime freeMemory

Introduction

In this page you can find the example usage for java.lang Runtime freeMemory.

Prototype

public native long freeMemory();

Source Link

Document

Returns the amount of free memory in the Java Virtual Machine.

Usage

From source file:fedora.server.management.DefaultManagement.java

private void finishModification(DOWriter w, String method) throws ServerException {
    if (w != null) {
        m_manager.releaseWriter(w);/* w ww .  j a v a 2s . co  m*/
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Exiting " + method);
        Runtime r = Runtime.getRuntime();
        LOG.debug("Memory: " + r.freeMemory() + " bytes free of " + r.totalMemory() + " available.");
    }
}

From source file:com.inverse2.ajaxtoaster.AjaxToasterServlet.java

private void returnHealth(HttpServletResponse response) throws Exception {

    StringBuffer healthInfo = new StringBuffer();

    healthInfo.append("AjaxToaster version " + getVersion() + "<br>");
    healthInfo.append("Using XMLToaster version " + com.inverse2.xmltoaster.Version.getVersion() + "<br>");
    healthInfo.append("Properties file name [" + propertiesPath + "]<br>");
    healthInfo.append("Script directory [" + scriptPath + "]<br>");
    healthInfo.append("Logging method [" + loggingType + "]<br>");
    healthInfo.append("Sleep interval [" + sleepInterval + "]<br>");
    healthInfo.append("<br>");
    healthInfo.append(serviceMapper.getURIMappings().replaceAll("\\n", "<br>"));
    healthInfo.append("<br>");

    healthInfo.append("List of operations available;<br><br>");

    List<ServiceOperationInfo> serviceList = servicePool.getOperationInfo();
    ServiceOperationInfo operation;/*from  w  w w  .  j  ava  2s. co  m*/

    for (Iterator<ServiceOperationInfo> it = serviceList.iterator(); it.hasNext();) {
        operation = it.next();
        healthInfo.append("-- " + operation.getServiceName() + "/" + operation.getOperationName() + "<br>");
    }

    Runtime rt = Runtime.getRuntime();

    healthInfo.append("<br>JVM: Total Mem [" + rt.totalMemory() + "], Free Mem [" + rt.freeMemory()
            + "], Max Mem [" + rt.maxMemory() + "]<br>");

    writeResponse(healthInfo.toString(), "HTML", null, response);
}

From source file:com.aurel.track.itemNavigator.ItemNavigatorAction.java

private long getUsedMemory() {
    Runtime rt = Runtime.getRuntime();
    long mbyte = 1024L * 1024;
    return (rt.totalMemory() - rt.freeMemory()) / mbyte;
}

From source file:com.aurel.track.itemNavigator.ItemNavigatorAction.java

private void checkMemory(long usedOld) {
    Runtime rt = Runtime.getRuntime();
    long mbyte = 1024L * 1024;
    long used = (rt.totalMemory() - rt.freeMemory()) / mbyte;
    if (rt.freeMemory() / mbyte < 100) {
        LOGGER.warn("Less than 100 MByte free memory available.");
    }//from ww w. ja  v  a 2 s  .c  o m
    LOGGER.debug("Used memory Delta: " + (used - usedOld) + " MByte");
    LOGGER.debug("Used memory total: " + used + " MByte");
}

From source file:org.fcrepo.server.management.DefaultManagement.java

private void finishModification(DOWriter w, String method) throws ServerException {
    if (w != null) {
        m_manager.releaseWriter(w);//  w  w  w. ja  va 2s.  c o m
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Exiting " + method);
        Runtime r = Runtime.getRuntime();
        logger.debug("Memory: " + r.freeMemory() + " bytes free of " + r.totalMemory() + " available.");
    }
}

From source file:edu.stanford.muse.util.Util.java

public static String getMemoryStats() {
    Runtime r = Runtime.getRuntime();
    System.gc();/*from   w w  w.  ja v a2s.  c o m*/
    int MB = 1024 * 1024;
    return r.freeMemory() / MB + " MB free, " + (r.totalMemory() / MB - r.freeMemory() / MB) + " MB used, "
            + r.maxMemory() / MB + " MB max, " + r.totalMemory() / MB + " MB total";
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * {@inheritDoc}/*from  w w w  .java 2 s  .  co  m*/
 */
@Override
public void finalize(boolean finalizeGroups, ForceField forceField) {
    setFinalized(false);
    if (finalizeGroups) {
        bondTime = 0;
        angleTime = 0;
        stretchBendTime = 0;
        ureyBradleyTime = 0;
        outOfPlaneBendTime = 0;
        torsionTime = 0;
        piOrbitalTorsionTime = 0;
        torsionTorsionTime = 0;
        ArrayList Polymers = getAtomNodeList();
        for (ListIterator li = Polymers.listIterator(); li.hasNext();) {
            MSGroup group = (MSGroup) li.next();
            if (logger.isLoggable(Level.FINE)) {
                logger.fine(" Finalizing bonded terms for polymer " + group.toString());
            }
            try {
                group.finalize(true, forceField);
            } catch (Exception e) {
                String message = "Fatal exception finalizing " + group.toString();
                logger.log(Level.SEVERE, message, e);
                System.exit(-1);
            }
            if (logger.isLoggable(Level.FINE)) {
                Runtime runtime = Runtime.getRuntime();
                long occupiedMemory = runtime.totalMemory() - runtime.freeMemory();
                long MB = 1024 * 1024;
                logger.fine("\n In-Use Memory   (Mb): " + occupiedMemory / MB + "\n Free Memory     (Mb): "
                        + runtime.freeMemory() / MB + "\n Total Memory    (Mb): " + runtime.totalMemory() / MB);
            }
        }
        for (MSNode m : molecules.getChildList()) {
            Molecule molecule = (Molecule) m;
            molecule.finalize(true, forceField);
        }
        for (MSNode m : water.getChildList()) {
            Molecule molecule = (Molecule) m;
            molecule.finalize(true, forceField);
        }
        for (MSNode m : ions.getChildList()) {
            Molecule molecule = (Molecule) m;
            molecule.finalize(true, forceField);
        }
        if (logger.isLoggable(Level.FINE)) {
            StringBuilder sb = new StringBuilder("\n Time to create bonded energy terms\n\n");
            sb.append(String.format(" Bond Streching     %10.3f\n", bondTime * 1.0e-9));
            sb.append(String.format(" Angle Bending      %10.3f\n", angleTime * 1.0e-9));
            sb.append(String.format(" Stretch-Bend       %10.3f\n", stretchBendTime * 1.0e-9));
            sb.append(String.format(" Urey-Bradley       %10.3f\n", ureyBradleyTime * 1.0e-9));
            sb.append(String.format(" Out-of-Plane Bend  %10.3f\n", outOfPlaneBendTime * 1.0e-9));
            sb.append(String.format(" Torsionanl Angle   %10.3f\n", torsionTime * 1.0e-9));
            sb.append(String.format(" Pi-Orbital Torsion %10.3f\n", piOrbitalTorsionTime * 1.0e-9));
            sb.append(String.format(" Torsion-Torsion    %10.3f\n", torsionTorsionTime * 1.0e-9));
            logger.fine(sb.toString());
        }
    }
    if (!java.awt.GraphicsEnvironment.isHeadless()) {
        createScene(!finalizeGroups);
        center();
    }
    removeLeaves();
    setFinalized(true);
}

From source file:de.hpi.fgis.hdrs.node.Node.java

@Override
public NodeStatus getNodeStatus() {
    Runtime rt = Runtime.getRuntime();
    return new NodeStatus(rt.freeMemory() + (rt.maxMemory() - rt.totalMemory()), bufferSize.get(),
            conf.getInt(Configuration.KEY_NODE_TRANSACTION_BUFFER,
                    Configuration.DEFAULT_NODE_TRANSACTION_BUFFER) - transactionMemPool.availablePermits(),
            segments.size(), transactions.size(), scanners.size());
}

From source file:org.pentaho.di.core.Const.java

/**
 * Return the percentage of free memory for this JVM.
 *
 * @return Percentage of free memory./* w  w w .j  av  a 2  s. c o m*/
 */
public static final int getPercentageFreeMemory() {
    Runtime runtime = Runtime.getRuntime();
    long maxMemory = runtime.maxMemory();
    long allocatedMemory = runtime.totalMemory();
    long freeMemory = runtime.freeMemory();
    long totalFreeMemory = (freeMemory + (maxMemory - allocatedMemory));

    int percentage = (int) Math.round(100 * (double) totalFreeMemory / maxMemory);

    return percentage;
}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public Bitmap resizedbitmaponmemorycheck() {
    int width = (int) view.bitwidth[view.fp];
    int height = (int) view.bitheight[view.fp];

    final Runtime rt = Runtime.getRuntime();
    Log.d("free memory, maxmemory, total memory",
            rt.freeMemory() + " " + rt.maxMemory() + " " + rt.totalMemory());
    final long freeMem = rt.freeMemory() + (rt.maxMemory() - rt.totalMemory());
    File file1 = new File(Tabs1.floorplanstrings.get(view.fp));
    double ratio = 0.50;

    long myResourceSize = file1.length();

    Bitmap canvasbitmap;//from   w w w  .  ja  va 2s .  com
    //canvasbitmap = Bitmap.createBitmap(width, height,
    //      Bitmap.Config.ARGB_8888);
    Log.d("width and height", u.s(width) + " " + u.s(height));
    Log.d("myResourceSize, freeMem, ration", myResourceSize + " " + freeMem + " " + ratio);

    if (!u.isbluestacks()) {
        Log.d("not bluestacks", "true");
        ///This is where the app get out of memory error!!!

        canvasbitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    } else {

        FINALBITMAPSCALE = 4;
        Log.d("bluestacks", "true");
        canvasbitmap = Bitmap.createBitmap(width / FINALBITMAPSCALE, height / FINALBITMAPSCALE,
                Bitmap.Config.ARGB_8888);

    }

    return canvasbitmap;
}