"JAVA" Runtime

Source: Internet
Author: User
Tags terminates

1, memory management:
Java provides a mechanism for automatic collection of useless units. The TotalMemory () and Freememory () methods allow you to know how large the heap memory of an object is, and how much remains.
Java periodically reclaims garbage objects (unused objects) in order to free up memory space. However, if you want to collect obsolete objects before the next specified period in the collector, you can run the garbage collector as needed by calling the GC () method. A good test method is to call the GC () method first, then call the Freememory () method to see the basic memory usage, then execute the code, and then call the Freememory () method again to see how much memory is allocated. The following program demonstrates this idea.  public static void Main (string[] args) {  runtime.getruntime (). GC ();   Long a = Runtime.getruntime ( ). TotalMemory ();  long a1= runtime.getruntime (). Freememory ();  long a2= a-a1;  System.out.println ("s=" +A2);  list<subscriber> s=new arraylist<subscriber> ();  for (int i = 0; i < 50000; i++) {  & nbsp Subscriber Sb=new Subscriber ();   sb.setid (111l);   sb.setname ("1231231");   s.add (SB ); }  Runtime.getruntime (). GC ();  Long B = runtime.getruntime (). TotalMemory ();  long b1= Runtime.getruntime (). Freememory ();  long b2= b-b1;  System.out.println ("e=" +b2);  System.out.println (B2-A2);  System.out.println ((B2-A2)/1024/1024);   } 

Second, API preview
Addshutdownhook (Thread Hook)
Register a new virtual machine to close the hook.
Availableprocessors ()
Returns the number of available processors to the Java virtual machine.
EXEC (String command)
Executes the specified string command in a separate process.
EXEC (string[] cmdarray)
Executes the specified commands and variables in a separate process.
EXEC (string[] cmdarray, string[] envp)
Executes the specified command and variable in a separate process for the specified environment.
EXEC (string[] cmdarray, string[] envp, File dir)
Executes the specified commands and variables in a separate process that specifies the environment and working directory.
EXEC (String command, string[] envp)
Executes the specified string command in a separate process in the specified environment.
EXEC (String command, string[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.
Exit (int status)
Terminates the currently running Java virtual machine by starting the shutdown sequence of the virtual machine.
Freememory ()
Returns the amount of idle memory in a Java virtual machine.
GC ()
Run the garbage collector.
InputStream Getlocalizedinputstream (InputStream in)
is obsolete. Starting with JDK 1.1, the preferred way to convert a local coded byte stream to a Unicode character stream is to use the InputStreamReader and BufferedReader classes.
OutputStream Getlocalizedoutputstream (OutputStream out)
is obsolete. Starting with JDK 1.1, the preferred way to convert a stream of Unicode characters to a local coded byte stream is to use the OutputStreamWriter, BufferedWriter, and PrintWriter classes.
GetRuntime ()
Returns the run-time object associated with the current Java application.
Halt (int status)
Forcibly terminates the currently running Java virtual machine.
Load (String filename)
Loads the specified file name as a dynamic library.
LoadLibrary (String libname)
Loads a dynamic library with the specified library name.
MaxMemory ()
Returns the maximum amount of memory that the Java virtual machine is attempting to use.
Removeshutdownhook (Thread Hook)
Unregister a previously registered virtual institution closed hook.
Runfinalization ()
The terminating method for all objects that are running pending finalization.
Runfinalizersonexit (value)
is obsolete. This method itself has no security. It may invoke the finalization method on the object being used, while other threads are manipulating these objects, resulting in improper behavior or deadlock.
TotalMemory ()
Returns the total amount of memory in the Java virtual machine.
Traceinstructions (ON)
Enable/disable command tracking.
Tracemethodcalls (ON)
Enables/disables method call tracing.

"JAVA" Runtime

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.