Day24: Multithreading "Wait for wake-up mechanism"
Wait for wake mechanism [Object]
Wait (): Leave the thread in a wait state
Notify (): Wake-up waiting thread
When implementing or overriding a parent class method, the subclass can only try catch if there are exceptions that are not in the parent class.
Wait (): is a method of the object class and can be used without a reference; Release the lock object
Sleep (): is a static method of the thread class that needs to pass arguments; Do not release lock objects
Thread Priority
Getproirity (): Gets the priority, the default setting is 5, and the range is [1,10]
Setproirity (): Set priority
Note: Priority can be increased to a certain extent, and a small amount of data is not obvious.
Threading Extensions:
To pause a thread:
public static void Yeiod ()
Make threads more harmonious, but not fully guaranteed---"Wait for wake-up mechanism"
Join Thread:
Public final void Join ():
Once there is a join () thread, the other thread must wait until the thread finishes executing
Start the thread to join before joining the current boot thread.
Daemon Thread:
Public final void Setdaemon ();
The main () method is a thread
Sets the thread as the daemon thread, and once the foreground thread ends, the daemon thread ends
Network programming:
Socket programming
Network overview
Resource sharing and information transfer--network operating system, network management software, network communication protocol
Network model:
OSI Reference Model
Physical Layer--bitstream, Data link layer--switch, network layer--router, Transport layer--Protocol and port
Session Layer--session, presentation layer--encryption and decryption, compression decompression, application Layer--application software
TCP/IP Reference Model
Application layer, Transport layer, internetwork layer, host to network layer
Three elements of network communication:
Ip:
"Dotted decimal"
IP Address classification: "Five Classes"
IP address = network number + host address
View Native ip:ipconfig--View network IP Ping---see if there is a problem with the network
Ping 127.0.0.1 Test native network environment
Ping 192.168.x.x
Port number:
Logical port
A: Each network program will have at least one logical port
B: The logical address used to mark the process, different processes are marked differently;
C: Valid port: 0~65535, where the 0~1024 system uses or retains the port.
UDP and TCP protocols: "Rules"
Udp:
A: Data packaging;
B: Data is limited;
C: for no connection;
D: unreliable;
E: Fast Speed
QQ Chat Room (group chat)
Tcp:
A: Establish A connection channel;
B: Data is unrestricted;
C: Connection-oriented (three-time handshake);
D: Reliable;
E: Slow speed
Bluetooth, QQ single chat, call
"Apply on Demand"
Socket programming: "Socket programming, network Programming"
Provides a mechanism for network programming that wraps ports and IP addresses
Characteristics:
sockets at both ends;
Network communication is actually the communication between sockets;
Data is transmitted over an IO stream between two sockets
InetAddress:
No construction method
A: The members are static
B: Return inetaddress Instance Object
Member Methods:
Get localhost: getlocalhost
Get any host: getbyname (String IP)
Host Name: GetHostName
Host IP Address: gethostaddress
Programming under the UDP protocol:
Create a socket service object; datagramsocket
Create the data and package the data; datagrampacket
Send data;
Close Resource
Note: The ports must be consistent,
Chat room
"Applications: Network programming, IO, multithreading"
Udp
1. Encapsulate the data source and destination into a packet;
2. There is no need to establish a connection;
3. The size of each datagram is limited to 64k;
4. The agreement is unreliable because there is no connection;
5. No need to establish a connection, fast.
Tcp
1. Establish a connection to form a channel for transmitting data;
2. Large data transfer in connection (unlimited data);
3. Complete the connection by three handshakes;
4. is a reliable agreement;
5. The connection must be established and the efficiency will be slightly lower.
Java Basics-Day 24th