Java Applet Getting Started 20

zhaozj2021-02-11  217

Getting started with Java Applet

YY435

Pacific Network Academy

Fifth day

Thread

The example of the program we given is basically single-threaded. This is what the thread to tell you today.

Multi-curable refers to the simultaneous executives, and work together with several different implementation routes. In the Java language, there is an important feature that its built-in multi-threaded support, which makes it easy to develop a multi-thread function that can handle multiple tasks at the same time.

A few concepts of a .java thread

1) Program, process and thread relationship is a static code, which is the fundamental of application software execution. The process is a dynamic execution process of the program. It corresponds to a complete process that is loaded from the code, executes the execution, which is also the process of the process itself from the generation and development to the demise. As the same program for executing the blueprint, it can be loaded into different memory regions of the system to perform different processes, respectively, form different processes. The thread is a smaller execution unit than the process. A process can generate multiple threads in its execution process, forming a plurality of execution clues. Each clue, that is, each thread also has its own generation, existence, and dying process, as well as a dynamic concept.

2) Thread turntable and lifecycle each Java program has a default main thread. For Application, the main thread is the clue executed by the main () method. For Applet, the main thread command browser loads and executes the Java applet. To achieve multi-thread, you must create a new ready-made object in the main thing. Java language uses Thread class and its own self-class object to represent threads, new threads usually have five states in its complete life cycle: new: new thread objects are new, at this time, it There is already corresponding memory space and other resources, and has been initialized. Ready: After the thread in the new state is started, you will enter the thread queue to wait for the CPU time film, and it has a condition that is running. Once the wheel is turned to the CPU resource, it can be separated from the main thread that created it and starts its own life cycle. In addition, the thread that is in a blocking state is also entered after the inclusion is blocked. Run: When the thread of the ready state is scheduled and obtained the processor resource, it will enter the operating state. Blocking: A thread that is executing is in some special cases, letting the CPU and temporarily terminate its execution and enter the sleep state. Death: The dust in the death state does not have the ability to continue to operate. There are two reasons for thread death: one is the ready-made ready-made completion of it. Another one is to terminate the thread in advance, such as terminating the thread by performing a STOP () method or DESTROY ().

Ok, I have said so much, or give you a few examples, the cooperation example gives you the beginning of the thread!

Er. Java thread

This example only shows you the inside of the system, two uninterrupted threads. From this example you can see how many times each is executed! Click here to view the source code and explain

转载请注明原文地址:https://www.9cbs.com/read-4719.html

New Post(0)