First, you have to say this class
Org.apache.tomcat.util.net. jioendpoint, which is responsible for all TCP request connections, implements a server mode and enables a background listener
The thread is responsible for receiving the incoming socket, then extracting the response worker from the thread pool, throwing it to the worker for processing, and listening on its own. Secondly, worker is responsible for processing
A socket thread starts to enter the Tomcat world with user requests. By default, there are a total of 200 workers, that is, a maximum of 200 threads. After processing a request
The thread will not be destroyed, but will enter wait blocking, and the object of this thread will not be destroyed. It is entered into a stack and corresponds to the data structure of the workstack. Every time the receiving thread
When getting a socket, we will first take out an existing thread object from the stack, and then use the Assign Method of the object to give the socket to it, and call notify
Wake up the worker processing thread. In the future, we will be able to use its implementation methods for small servers. A friend who is studying multithreading can definitely learn this class thoroughly!
Correspondingly, there is another
Org.apache.tomcat.util.net. nioendpoint, which is similar to the previous function, but the NIO package API has the largest
The difference is that after the receiving thread receives a socket, it may put the socket into the cache pool first, and then the worker takes the socket from the pool for processing.
The functions and performance will be improved a lot, but the code lines are more than 2 K, which is quite complicated and not well-designed. If you are interested, you can study them.
Org. Apache. tomcat. util. Buf. messagebytes: This is
Why is a string processing class close to the underlying layer because the socket receives the byte type while Java uses the char or string type?
Encoding and performance problems are involved. Therefore, all the information received by the socket is represented by this class. Only when the string is output will the bytes in the string be converted, implement a latency
The load lazy mode is used by the request class at the bottom layer of Tomcat to store data in large quantities. Let's take a look at the request class:
- Private
Messagebytes
Methodmb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Unparsedurimb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Urimb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Decodedurimb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Querymb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Protomb
=
Messagebytes
.
Newinstance
()
;
-
// Remote address/Host
Private
Messagebytes
Remoteaddrmb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Localnamemb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Remotehostmb
=
Messagebytes
.
Newinstance
()
;
Private
Messagebytes
Localaddrmb
=
Messagebytes
.
Newinstance
()
;
Private
Mimeheaders
Headers
=
New
Mimeheaders
()
;
Maybe you will think that the performance of constructing so many classes will be high. In fact, this is not the case. We will not stop constructing and destroying classes.
The object does consume a considerable amount of performance, but it is perfect if an object is constructed and can be reused. This class is designed like this, and there is a way to recycle resources, call
Recycle (), this method can clear the array, clear the object in, instead of destroying itself, because the object that uses it, as long as you call recycle, can be used again later
.
Messagebytes actually has two built-in important
Class, org. Apache. tomcat. util. Buf. bytechunk and
Org. Apache. tomcat. util. Buf. charchunk. These two classes bring us back to the c age. Why do we say this? Because it is simply a string processing
Class, some familiar algorithms are all eye-catching, such as the character-to-match algorithm, indexof, startswith, to determine whether the character conversion is equal, search for characters, and so on.
Better performance and more powerful functions (this sentence has been said, haha)
There is also a practical data structure worth learning
Yes, org. Apache. tomcat. util. Buf. ASCII. If you know about table-driven friends, you must be familiar with this class. Is it case sensitive? Determine whether the ticket is in English
Word? Is it a blank character? Determines whether it is a number, converts the byte type to the Int or long type, converts the case to the case, and so on. These are all exercises for university computer courses.