Java IO... It's really the high-level language I've ever seen. The most complicated ...
Looking at this picture, I was drunk.
But unknowingly,java io has been updated to the nio.2 ,io Library has been more than this, then the process, they experienced how the change? Before we get to know Java 's IO , let's look at several models.
We 're offering exclusive services .
The IO model used byJava is the BIO(Block Input Output) model before the JDK is launched. So what is a BIO model?
Simply speaking, one-to-one service. Like a new restaurant, a guest, buy a table and put it in the dining room (there should be no such stupid boss.) Orz ..... ), for 1000 guests, put 1000 tables on the table ...
" I go, the restaurant is not big enough ...." How did it break? ”
This time only wayward ...
" buy and buy!" Let's rent another venue and open a new store! ”
This is the traditional BIO model, rather "wayward" model, the server will use a acceptor thread to listen to the client's connection, whenever a client to the server to initiate a link, the server creates a thread (thread ), when the number of concurrent visits increases, only through the "Buy Buy buy" method to solve the problem.
So here's the problem,t^t.
" It was just a dream!" We are so poor. ”
the enlightened boss
"Why don't we just get a automatic arranging?" ”
I have so many tables, have bought in advance, every time guests sit full, after the guests can only wait outside (no way, who let our food is so delicious!). )。
This is the pseudo-asynchronous IO model. When the client initiates a request for a server, the server encapsulates the request into a task(Task) into the thread pool (threadpool) that was prepared before. When the number of concurrent requests exceeds the size specified by the thread pool, the thread that originated later can only silently wait in the queue for resources in the thread pool.
Compared to the BIO model, this model has improved a lot of performance.
But.. He's still a pseudo-async IO model! Perhaps the fame is too big. More and more guests are admiring. The door and other areas to be squeezed out AH ~ ~ If each table of customers eat time is longer (io is blocked, need to wait for io to complete before releasing resources), I can't hold!
It's time for us to show our wisdom.
We have updated the restaurant's automatic arranging system, and we also have a lot of fun in order to release the maximum energy from the limited space. We are beginning to realize that guests like our food, so let the guests enjoy our food in time is the most important (PM , clear needs analysis is very important AH!) )。
We put the automatic arranging system on the Internet, we can order takeout. Guests in advance to order the food needed, we put the food ready to send to the guests (the service is very intimate, there are wood!) )。 During this time, the guests can do their own things, and not because of waiting too long to feel irritable.
Yes, this is new IO , java After the 1.4 versions, Provides a new io Library, Of course in jdk1.7 , nio has been upgraded to nio.2 . After the client makes the request, the request returns immediately. When the server has the data ready, the data is sent back to the client. (can look at my previous blog " please call Me NIO )
Summary
Here is a simple analysis of several IO models, Next, I will combine some code to continue to write a few blog.
Finally, I hope there is no such a brain-free restaurant in the world
I just want to open a hotel. Evolution of--javaio Model