A summary of the multi-threading and Java Runtime Environment

Source: Internet
Author: User
Tags throw exception

The operating system is the platform that provides the software to run the environment, the software running on the system is a process, considering the security problems they can not share data, so is the process. Threads are included in the process, and they can share data between them.

The Java language has its own environment it is Jre,jre is a JVM (Java Virtual machine) and JDK (Java Development Kit), the JVM has a compiler and interpreter, The compiler converts. Java types of files to. class files, and then the interpreter converts the. class file from a section of the JDK into a byte code that the system can recognize, and then the system converts the bytecode into a computer-recognized binary code.

Several mechanisms that the virtual machine comes with:

1, garbage collection mechanism, Java Virtual machine comes with application management memory,

The function of the System.GC () method is simply to wake up the garbage collection mechanism, the garbage collection principle is the tag Exchange area collection algorithm, (in the stack top-down two searches, the first time if there is a long time not used or the object is now empty is blank to mark, in the second search, If it is still not used for a long time, or empty, immediately clean up the release of resources after the execution of the GC () method can not immediately dispose of garbage, he is a thread, and the level is the lowest, to wait until the CPU resources are preempted to clean up, the real way to clean up the garbage is the Finalize () method, Garbage collection is not a programmer, if you want to clean the current object, you can first empty, in the call System.GC () method, the last This.finalize () method

2, exception handling mechanism, Lang packet in the Throwable class of the direct subclass has two, one is exception, one is error,exception and is divided into two kinds of one is the run-time exception, one is the inspection period anomaly, check type exception is a compiler directly capture, Run-time exceptions are exceptions that are caught by the interpreter.

If an exception in the method is not resolved, throw, with the throw exception object, when calling the method if the exception is still not resolved to discard the exception, the second time is throws, written after the class name. Job coordinates www.zhizuobiao.com

3. Multithreading

Threads contain three states:

1, create a state, wake up the thread by the start () method, so that the thread is in the thread queue

2, the running state, when this thread preemption to the CPU resources, it will callback the run () method

3, blocking state, the blocking state can have two methods to implement the wait () thread will not know that there is notify (), or the Notify () method wakes up in the threads queue,

Sleep () thread

Also waits in the thread queue to preempt CPU resources at the specified time

Thread destruction: 1, isAlive () determine if the thread is still alive

2. Yield () destroy

A summary of the multi-threading and Java Runtime Environment

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.