(Tutorial) Determine the available memory in Java
Tutorial : Determine the available memory in Java
This tutorial will give you a brief walk through on Java memory use in the sandbox and show how to use the Runtime class to discover the amount of memory available to your Java applet or application.
The Sandbox
Unlike a C++ application, a Java applet or application doesn't have access to all the memory on the computer. Instead, Java creates a sandbox that limits the amount of available memory available to your application. The sandbox was created to protect the user from Java code that could be harmful by using all of the available resources on a computer. By default, the JVM uses a percentage of the available system memory when your Java application or applet starts. This will vary be different versions of the JVM.
You can increase the default amount of memory available to the JVM by using the -Xmx command line option for Java applications. For Java applets, the command line setting can be set in the Java control panel. For more information on the -Xmx command line option, enter java -X on the command line.
The following example uses the Runtime class to get the maximum amount of memory (sandbox limit) that your Java application can use..
Courtesy: Codebeach.com
- guru's blog
- Login to post comments
