Linear state; thread-safety issues

Linear state a total of five:

2. 1. nascent state running state ready state 3. 4. 5. blocking state End state

note:

1. After restoring blocked instead of running into the ready state, upon termination can not be restored

2.sleep () (holding resource sleeping) - does not release the object lock, cpu resource release

3.yield () - let the thread

4.join () - to jump the queue thread - a thread end and then wait to start the next process

5.Thread.State getState () - Returns this thread's state

6.setPriority (int newPriority) to change the thread priority; priority getPriority () returns the thread.

Thread-safety issues

Genlock: synchronized

Synchronization method: use the method (static members can be) - a simple, but a wide range, can be inefficient

Sync blocks: a code synchronization - the complexity, some code range locks, lock the lock what conditions -> this, class, resources (reference data type members custom properties), depending on the particular advantages and disadvantages of business logic

Lock "class" --synchronized (Single.class) - Single.class class object, every class there is only a class of objects - lock the class, which is equivalent to all object classes are locked, efficiency lower

Lock "resources" - provided resources, member properties, lock to lock the same thing, object reference data type of a custom forever

network programming

ip: Special IP node on the network definition: internal IP 192.168.0.0 ~ 192.168.255.255 tissue, non-registered IP

Port: 2-byte distinguishing software to 65535 Reserved port numbers 0: 80: http 8080: tomcat 1532: oracle 3306: mysql

url: Uniform Resource Locator

Agreement: means of communication - resource transport layer: tcp and udp

udp: connectionless protocol simple, small overhead, high efficiency is usually not more than 60k based unsafe byte array

tcp: low efficiency for secure connection based on the 3-way handshake 1: 2 transmission request response based on the transmission data 3. io stream

udp realize sending side:  

1. DatagramSocket (int port) defined in the transmitting end  

2. Prepare data  

3. The data package DatagramPacket (byte [] buf, int offset, int length, SocketAddress address)  

4. The transmission data void send (DatagramPacket p) data packets sent from this socket packet.

5. Resources Close

udp realize the receiving end:  

1. Definitions receiving end  

2. Prepare the parcel, the received data  

3. Receive   

4. Close

  

Guess you like

Origin www.cnblogs.com/lingxi2b2/p/11997340.html