在每一个实例下,我运行一个简单的程序,测定循环调用一个方法10,000,000次所需的运行时间,我调用了同步和非同步两个版本,并比较了结果。
In each case, I ran a simple program that measured the run time of a loop calling a method 10,000,000 times, calling both a synchronized and an unsynchronized version, and compared the results.
对一个空方法的同步调用可能要比对一个空方法的非同步调用慢20倍,但我们多长时间才调用一次空方法呢?
A synchronized call to an empty method may be 20 times slower than an unsynchronized call to an empty method, but how often do we call empty methods?
如果同步化成功了,那么同步化开始的时间将会得到保存以在下一次运行期间使用,从而决定需要同步化哪些内容。
If synchronization was successful, the time at the beginning of the synchronization will be saved to be used during the next run to determine what needs to be synchronized.
应用推荐