Management package in java consists of classes that has managed beans for environment of JAVA in the system. The following is a small example of what this Management package can do:
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Toworld {
public static void main(String args[]){
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
Method[] methods = OperatingSystemMXBean.class.getDeclaredMethods();
for( int nMethodCntr = 0; nMethodCntr < methods.length ; nMethodCntr++ )
{
Method method = methods[nMethodCntr];
try
{
System.out.println(method.getName()+": "+method.invoke(os));
}
catch( IllegalArgumentException e )
{
e.printStackTrace();
}
catch( IllegalAccessException e )
{
e.printStackTrace();
}
catch( InvocationTargetException e )
{
e.printStackTrace();
}
}
}
}
The following will be the output:
getName: Linux
getAvailableProcessors: 4
getArch: amd64
getVersion: 3.6.11-4.fc16.x86_64
getSystemLoadAverage: 0.25
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Toworld {
public static void main(String args[]){
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
Method[] methods = OperatingSystemMXBean.class.getDeclaredMethods();
for( int nMethodCntr = 0; nMethodCntr < methods.length ; nMethodCntr++ )
{
Method method = methods[nMethodCntr];
try
{
System.out.println(method.getName()+": "+method.invoke(os));
}
catch( IllegalArgumentException e )
{
e.printStackTrace();
}
catch( IllegalAccessException e )
{
e.printStackTrace();
}
catch( InvocationTargetException e )
{
e.printStackTrace();
}
}
}
}
The following will be the output:
getName: Linux
getAvailableProcessors: 4
getArch: amd64
getVersion: 3.6.11-4.fc16.x86_64
getSystemLoadAverage: 0.25
No comments:
Post a Comment
Note: only a member of this blog may post a comment.