I am a thread

Source: Internet
Author: User

I was a thread, I was born a number: 0x3704, and then led to a dim room, here I found a lot of my identical companions. My companion 0x6900 for a long time, he said to me with the vicissitudes of life: Our Thread of destiny is to deal with the package. After finishing the package, you have to come back here soon, or you may never come back. My face is ignorant, parcel, what parcel? "Don't worry, you'll see right away, we don't have any idlers here." “

Sure enough, before long, the door of the house opened, and a ferocious-looking fellow shouted, "0x3704, come out!" "I was stuffed with a heavy parcel as soon as I came out, with a piece of paper full of steps. "Go on, take care of this parcel." "Where to deal with" "Follow the instructions, go first to the ready workshop" Sure enough, there is an indicator arrow on the ground, followed it to a bright big room, where there are many threads, and everyone is very nervous, like always ready to go forward.

       I just came in, I heard the radio said:" 0x3704, enter the workshop "I hurried forward, a lot of people behind the argument said:" He was so lucky, Does it matter if you just go into the ready state to run? "Not, you see people's priority is how high ah, alas," the front is the workshop, here is simply too beautiful, no wonder the old thread always nagging said: If you can stay here just fine. Here space, good vision, fresh air, flowers, and a lot of people have never seen, like waiters waiting for me to serve. They also have numbers, and more importantly, everyone has a label that says: HDD, database, memory, Nic ... I can not understand now, look at the operation of the steps: The first step: Remove the parameters from the package   Open the package, there is a HttpRequest   object, you may take the UserName, password two parameters; Step two: Perform a login operation. AO, originally is someone to login ah, I put username/password to the database waiter, he took data, slowly away. Why is he so slow? But am I just going to be able to stay in the workshop for a little while? It's not going to be a third step anyway. Just then, the broadcast in the workshop rang: "0x3704,   I am the CPU, remember the steps you are taking, take the parcel away immediately." I started slowly, "hurry up, the other threads are coming in soon".

Leave this workshop and come to a big house, where many threads slowly tea and play cards. "Man, are you all right?" “。 "You new to the put, you do not know I am waiting for the database waiter to give me the data Ah!" It is said that they are hundreds of thousands of times times slower than we are and have a good rest here. So slow?   I have someone here in the system, can wait such a long time? "Rest assured, you have not heard of the human day, CPU a year, we are here with nanosecond, millisecond time, the human waiting for a second, equivalent to us for several days, and".

Simply sleep for a while, do not know how long, the Big Horn again began to broadcast:" 0x3704, your data came, quickly go to execute "I turned to the CPU shop run, found here the threads are only out! There are bursts of laughter sound: "Really is new, do not know to be ready to go to the workshop, etc." so hurriedly to the Ready workshop, this time is not so good luck, and so long before being called into the CPU workshop. While waiting, I heard someone whisper: "Have you heard that a thread has been killed recently?" "This guy relies on the CPU shop, the CPU utilization has been made into 100%, and then was killed" "kill off after where to go" "may be garbage collected it" I was in the heart of a shiver.   hurriedly continue to deal with, the rest of the action is much faster, the second step is successful, the third step: Build the Home page after the successful login. This step is a bit of time, because there is a lot of HTML to deal with, do not know the code who wrote, processing is very annoying. I was making a nervous production of HTML, the CPU began to call: "0x3704,   I am the CPU, remember the steps you are performing, immediately take the package away" "Why Ah" "Each thread can only run on the CPU for a period of time, to the time to let others use, you go to the Ready workshop, I'm waiting for you. "That's it, I've been ready--running these two states, I don't know how many times I've rotated, and I finally finished my work by the list of steps." Finally, the package containing the HTML was sent back.

As for what to do after login, I don't care. will be back to my dim room, really a little reluctant here. But I'm lucky to have some threads, and they're completely destroyed when they're done, and I'm still alive! Back to the little black House, the old thread 0x6900 asked: "How?" How did you feel on the first day? "Our world rules are complex, first of all you don't know when you will be picked to execute;"   Second, in the execution of the process may be interrupted at any time, let out the CPU workshop;   third, once the hard disk, the database such time-consuming operation also have to give up the CPU, to wait;   IV, that is the data, you do not have to execute immediately, but also waiting for the CPU to pick "" The lad understand good ah "I do not understand why many threads are executed dead, why are we still alive? "You don't know that immortality is our prerogative, we have an official name here, called the thread pool!" “。

The dull days were so day by day, as a thread, my daily life was to take the parcel, deal with the parcel, and then return to our Dim Home: Thread Pool. One day when I came back, I heard a brother say, today to have a good rest, tomorrow is the craziest day. I glanced at the calendar and tomorrow is November 11. Sure enough, 0 points just past, do not know those human how, crazy delivery package, in order to cope with the influx of massive parcels, line constructor no one can idle down, all go out to deal with the package. CPU Workshop utilization is super high, the hard disk is buzzing, the network card crazy Flash,   Even so, still processing, mountains. We have no way, it is too much, most of these packages are browse pages, place orders, buy, buy, buy.

Don't know how long it took, the parcel mountain finally slowly disappeared. Finally can catch breath, I think I will never forget this day. Through this event, I understand the world in which I am located: This is an e-commerce website! My daily job is to handle the user's login, browse, cart, order, payment. I asked the 0x6900 of the thread pool: "When are we going to work?" "Wait until the system restarts," 0x6900 said. "Have you ever experienced a system restart?" "How could that be?" , the system restart is our time of death, that is, the end of the world, once restarted, the entire thread pool is destroyed, time and space all disappear, all start again "" When will restart? "This is not good to say, enjoy the life in front of it ..." In fact, colorful life, my favorite package is to upload pictures, because the network is slow, so can be in the Ready workshop, CPU workshop for a long time, can know a lot of fun threads. For example, the last time I met memecached thread, he told me to cache a lot of user data through him, or distributed! It's on a lot of machines! I said no wonder later the login operation is so much faster, it is no longer from the database to fetch data from you there, ah, hey, you are distributed, you have been to other machines do not? He said how could I only send a get to that machine through the network every time, put command to access the data only, the others do not know. Like the last time I ran into a database connection thread when I was waiting, I knew it. He is also a connection pool, almost identical to our thread pool. He said that some of the packages were so perverted that it was exhausting to look at the order data for a year. I said pull it down you, you that is pure data, after you pass the data to me, I also have to assemble into HTML,   the workload does not know how many times larger than you. He said you have to work well with memecached, directly from him to take the data, as little as possible directly to call the database, our JDBC connection can also live easy point. I said yes, well, the point is you have to get the data in advance to cache ah, or I first ask the cache, no data, I do not have to find you? Life is like this, if you don't have a little fun yourself, what do you mean?

One day I met a horrible thing, almost died outside, back to the thread pool ... In fact, this distress I should be able to anticipate the right, too careless. The other day I handled some of the deposits and withdrawals from HTTP, and the old thread 0x6900 me: "Be very careful when handling these parcels, you must get a lock first, you must lock the account when you deposit or withdraw money from the account." Otherwise the thread will be in you waiting for the moment, sabotage, I was very coarse when young, and stabbed the crate. " In order to "scare" me, the kind 0x6900 gave me two tables: 1, no lock case, 2, lock the situation. I see the frightening, the original lock will bring such a serious accident. From then on to see the deposit, the package of withdrawals is more careful, fortunately, there has been no accident. Today I received a package is a transfer, from a famous actor's account to a famous director transfer money, specifically who I will not reveal, the amount is really not small. I follow the instructions of the old thread, must lock Ah, first the famous actor account lock, and then the famous Director account lock. Never thought of IS, there is a thread, yes, is 0x7954,   unexpectedly at the same time from the director of the transfer to this actor. So, there is a situation: just at the beginning I do not know what the situation, has been sitting waiting for the workshop silly, but wait too long, up to dozens of seconds! I have never experienced such an event. At this time I saw the thread 0x7954, he leisurely sitting there drinking coffee, I chatted with him: "Dude, I see you have 8 cups of coffee, why not go to work?" "Don't you drink 9 cups of tea?" "0x7954 replied. "I am waiting for a lock, I do not know which grandson has not been released" "I am also waiting for the lock ah, if I know which grandson does not release the lock I will not beat him to death" 0x7954 no weakness. I secretly took a look, this guy in his arms, holding me waiting for a director's lock? Obviously, 0x7954 also found that I was holding the lock he was waiting for. Soon we both quarreled, not to give: "Put your lock to me first, let me Finish" "No, never finished work to release the lock, now absolutely can not give you."

from the quarrel to the fight, just for a few seconds. More importantly, the two of us not only hold the lock of this famous director and actor, but also a lot of other locks, resulting in more and more threads waiting for the crowd to fill the room. Finally things really big, I have never seen the ultimate boss "operating system" also came. After all, the Big Boss is well-informed, he looked at one, hum, very disdain said: "There is a deadlock," "You two will kill one, come on, come over the lottery" This suddenly gave me a scare, so serious ah! I smoked the sign with trepidation, opened a look, is a "live" word. Alas, the small life finally saved. Poor 0x7954 was forced to hand over all the resources and was killed and disappeared. I got the director's lock and I can get to work. The big boss operating system disappears like wind, and only his voice is heard: Remember, we are here Director > actor,   in any case, to get the director's lock first. Because not only the director and the actor, but also many others, boss left a table,   inside is an algorithm, used to calculate the size of the resources, calculated, and always follow the way from the big to the small to obtain the lock: I went back to the thread pool, everyone knew my adventures, around me to ask a stop. Devils's thread dispatcher pasted the algorithm of the big Boss onto the wall. Every morning, we have to like the house intermediary without moral integrity, hairdressing shop waiter like, standing at the door, like being played monkey aloud recite: "Multiple resources lock to keep in mind, be sure to press the boss algorithm than the size, and then from the largest start lock"

After a lot of days, I and other threads found a strange thing: the handling of parcels is getting easier, no matter the package, whether it's logging in, browsing, saving .... The steps are all the same, returning a fixed HTML page. Once I stole a glance, it said: "The system will be from 00:00 to 4:00 maintenance upgrade, we are sorry for the inconvenience caused you." I went to tell the old thread 0x6904, he sighed and said: "Alas, our life is over, it seems that the system will be restarted soon, we will disappear, goodbye brother." "The moment the system restarts has finally arrived. I see things in the house are missing, waiting for the workshop, ready to shop, and even the CPU workshop has slowly disappeared. The thread brothers around me are getting less and more, and I'm the last one left. I shouted in the open wilderness: Is there anyone else? No answer.

Our generation thread pool has fulfilled its mission. The next-generation thread pool will soon be reborn.


I am a thread

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.