Java theory Java Multi-threading and network programming

Source: Internet
Author: User

Multithreading

One: The basic concept of multithreading:

1: Thread is a different execution path for a program

2: Process---Memory area code go to executable code, main method, main thread, real execution Way and code

Two: Create/Start a new thread:

1: Create---Create a new thread there is only one way: Implementing the Run () in runnable is the only way to create a new thread

(1) Create a class that inherits the Java.lang.Thread class: Class Exthr extends thread{}

(2) Create a generic class that implements the Runable () interface: Class Imprun implements runnable{}

2: Start---Start a new thread there is only one way: to invoke the Start () method in the thread class, which is the only way to start a new thread, to start another thread on the main thread: the object that created our thread in main

(1) in the main thread, create a Target thread class object, the target thread class is already thread, do not have to create the thread object, directly call the start () method can be

(2) in the main thread, create the thread class object, create the target thread class object, and pass in the thread object, create a new thread, call the start () method of the thread object, this is the start of a new thread

What we need to note is: Method invocation, start thread difference, only thread's start () method meeting call operating system API to create new thread

Three: State control:

1: State transitions:

(1): Create

(2): Start: Queue

(3): Ready, dispatch

(4): Blocking

(5): Run

(6): termination

2: Thread Control method:

(1): IsAlive (): Determine if the thread is still alive

(2): GetPriority (): Live Thread Priority

(3): SetPriority ()

(4): Sleep (): Sets the number of thread sleep milliseconds, static method

(5): Join (): Call a thread to the method, and merge with the current thread, that is, the execution is pointing to the execution of the current thread

(6): Yield (): Let go of the CPU time slice and wait again

(7): Wait ()

(8): Notify ()

(9): Notifuall

3: End a thread

(1): Interrupt: Interrupts closing a thread

(2): Defines a Boolean loop marker, False is even, run () stops, thread ends

---------------------------

Network programming

One: Network programming foundation, Network Communication protocol:

1:osi seven-layer model:

(1): Application layer

(2): Presentation layer

(3): Reply layer

(4): Transport Layer

(5): Network layer (IP)

(6): Data transfer layer (MAC)

(7): Physical layer

2:TIP/IP four-layer model:

(1): Application layer (application)

(2): Transport Layer (TCP/UDP)

(3): Network layer (IP layer)

(4): Physical/Data Link layer

Two: Socket (Network programming)---Operating system network programming is called this

---one end of the two links is called the socket

---Socket (network programming) in Java.net package

---TCP scoket communication model

---UDP socket communication model

Java theory Java Multi-threading and network programming

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.