Automatic returned object pool - a legend that is not beautiful

xiaoxiao2021-03-06  60

Automatic returned object pool - a legend that is not beautiful

Have a beautiful legend, beautiful stone, will sing ... "How fascinating thing (don't buy MP3), since there will be singing, so too many legend is born.

In the 11th issue of the programmer magazine, a piece of object pond title is << Automatic return >>, the author describes us a wonderful object pool that can be returned, so that every painful trash recycling programmer Brought the direction of heart.

But will the legend really become a reality?

Read all the articles, no schematic implementation code, all code snippets simply describe the principles mechanism for obtaining recyclable objects, such as I want to introduce to a high-performance httpserver, and then I tell you:

Serversocket sc = new serversocket (80); this can listen to the HTTP request link on 80.

I know that I can write Serversocket sc = new serversocket (80); if they can be written, can I write a few people in the webserver that can actually apply? Tell the legend to reality, I am welcome, I am afraid the author is just a dream. .

This is not important, because someone can make the legend a reality, do you have WebLogic, Resin, Tomcat ("Logist Not Super Three" is a moral) available, but it is not all beautiful to become a realistic legend. .

Java is an object-oriented idea. The process of programming for Java is the process of understanding of nature. Natural circles live in the back of life, each has to die. The whole world will not only work normally, and if there is one Unexpected death (this is not only every programmer is yearning), then hundreds of years later, it is a state of seeing everyone, what is the world?

Each Java object has its survival period. The life cycle of an object is not only managed by JVM, but also a homework system. The author has a constraint in his essays, we also Take a look at the legend of the legend is not beautiful for it.

We know that the true linked pool has realized the contraction function, that is, if there is a certain period of time, we destroy it, then generate new Connection, it is like this to live and die. The connecting pool works normally. If the legend has become a reality, Connection has become an unsatisfactory thing. When it is idle, it will always be connected with the database, and a database can be connected to the limit. When this application has no demand, other applications can not have too many links. Connecion is like a car, you applied for 40 vehicles, no matter what you do, don't want to use it. And actual Connecting the pool If I only need 10 vehicles, I will pay more than 30, when I need it, I will make Connecomion death, so that other opportunities for other applications have a moral programmer should follow the principles. Not, whether it needs to be alive.

On the other hand, if the object exceeds its life cycle, even if he is forcibly alive, it is just a walking dead, why don't you have to make him survive? The history of the garbage, indicating it has completed it. Mission, forcibly recover them from the garbage pile, the ghost resurrected the terrible situation everyone saw it on the screen?

Still in Connection (the original author has been explained by this object), its life cycle is not only managed by JVM, but also is constrained by the TCP protocol. If the contracted Connection is recycled from the garbage pile, we look How can it be? If this connection is idle and the database interaction, although it can be reroured from the garbage collector from the JVM, but in the protocol layer, the database server is idle because the socket link itself is idle. Hang a response to it. At this time, you will perform Command, "Connection Reset By Peer: Socket Writ", a thing that survives but no vitality (pure protein).

The world, life and death, can not be forced, the Chinese people are too innocent to think that "people are scheduled", they will force the pit in the mountains that do not coal. Change the nature's evil. We have foreseen or can be seen, that is, in destruction of humans I have, adapt to nature, protect nature, is the real beautiful legend.

转载请注明原文地址:https://www.9cbs.com/read-81990.html

New Post(0)