Friday, July 6, 2012

How to find default thread pool size programmatically

To find out jetty thread pool size programmatically :

ThreadPool tp = (ThreadPool) server.getThreadPool();
if(tp instanceof QueuedThreadPool) {
QueuedThreadPool qtp = (QueuedThreadPool) tp;
int minThreads = qtp.getMinThreads();
int maxThreads = qtp.getMaxThreads();
LOG.info("minThreads : " + minThreads + "\t maxThreads :" + maxThreads)
}

Tuesday, June 19, 2012

How to get RAM size using java?

package com.demo.memoryheap;

import java.lang.management.ManagementFactory;

/**
 * @author abdul
 *
 */
public class FreeMemoryUsingMxBean {

    /**
     * @param args
     */
    public static void main(String[] args) {
        com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
       
        System.out.println("Total Memory in MB: " + mxbean.getTotalPhysicalMemorySize()/(1024*1024));
       
        System.out.println("Free Memory in MB: " + mxbean.getFreePhysicalMemorySize()/(1024*1024));
    }
}

Note : If you get access restriction error while working on Eclipse , check this :
Access Restriction issue

Access restriction on class due to restriction on required library rt.jar for OperatingSystemMXBean ?

Its work for me :
  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select "Add Library" and select the JRE System Library. The default worked for me

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...