首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

计算机行业的变革速度

Something vaguely analogous has happened in the computer industry. Each new species (mainframe, minicomputer, personal computer, handheld, embedded computer, smart card, etc.) seems to go through the development that its ancestors did, both in hardware and in software. We often forget that much of what happens in the computer business and a lot of other fields is technology driven. The reason the ancient Romans lacked cars is not that they liked walking so much. It is be- cause they did not know how to build cars. Personal computers exist not because millions of people have a centuries-old pent-up desire to own a computer, but be- cause it is now possible to manufacture them cheaply. We often forget how much technology affects our view of systems and it is worth reflecting on this point from time to time. In particular, it frequently happens that a change in technology renders some idea obsolete and it quickly vanishes. However, another change in technology could revive it again. This is especially true when the change has to do with the relative performance of different parts of the system. For instance, when CPUs became much faster than memories, caches became important to speed up the "'slow" memory. If new memory technology someday makes memories much faster than CPUs, caches will vanish. And if a new CPU technology makes them faster than memories again, caches will reappear. In biology, extinction is forever, but in computer science, it is sometimes only for a few years.

03

如果把线程当作一个人来对待,所有问题都瞬间明白了

问题究竟出在哪里? 一个线程执行,固然是安全的,但是有时太慢了,怎么办? 老祖宗告诉我们,“一方有难,八方支援”,那不就是多叫几个线程来帮忙嘛,好办呀,多new几个不就行了,又不要钱。这样能管用吗?继续往下看。 俗话说,“在家靠父母,出门靠朋友”。有了朋友的帮助,就会事半功倍。是这样的吗? 不一定,如果朋友“不靠谱”,结果竟是在“添乱”。于是就演变为,“不怕神一样的对手,就怕猪一样的队友”。可见“人多力量大”纵然是对的,但也要配合好才能成事。 人和人是朋友,那线程和线程也是“朋友”,如果多线程之间不能配合好的话,最终也会变为“猪一样的队友”。事实证明,这也不是一件易事。且容我慢慢道来。 开发是一门技术,管理是一门艺术。也许你正想带着兄弟们大干一场,可偏偏就有人要辞职。或者你付出了这么多,但别人从来没有感动过。为什么会这样呢? 因为你面对的是人。每个人都是独立的个体,有思想,有灵魂,有情感,有三观。能够接受外界的“输入”,经过“处理”后,能够产生“输出”。 说白了就是会自主的分析问题,并做出决定。这叫什么呢?答案就是,主观能动性。 拥有主观能动性的物体(比如人),你需要和它协商着或配合着来共同完成一件事情,而不能“强迫”它去做什么,因为这样往往不会有好的结果。 费了这么多口舌,就是希望把问题尽量的简单化。终于可以回到程序了,那线程的情况是不是类似的呢?答案是肯定的。 一个线程准备好后,经过CPU的调度,就可以自主的运行了。此时它俨然成了一个独立的个体,且具有主观能动性。 这本是一件好事,但却也有不好的一面,那就是你对它的“掌控”能力变弱了,颇有一种“将在外,君命有所不受”的感觉。 可能你不同意这种看法,说我可以“强迫”它停止运行,调用Thread类的stop()方法来直接把它“掐死”,不好意思,该方法已废弃。 因为线程可能在运行一些“关键”代码(比如转账),此刻不能被终止。Thread类还有一些其它的方法也都废弃了,大抵原因其实都差不多。 讲了这么多,相信你已经明白了,简单总结一下: 事情起因:线程可以独立自主的运行,可以认为它具有主观能动性。 造成结果:对它的掌控能力变弱了,而且又不能直接把它“干掉”。 解决方案:凡事商量着来,互相配合着把事情完成。 作者观点:其实就是把线程当作人来对待。

04
领券