系统运维

一文弄懂Redis为什么这么快?

时间:2010-12-5 17:23:32  作者:IT科技   来源:系统运维  查看:  评论:0
内容摘要:复制publicclassConcurrencyTest{ privatestaticfinallongcount=1000000000; publicst

一文弄懂Redis为什么这么快?
复制public class ConcurrencyTest {      private static final long count = 1000000000;      publicstatic void main(String[] args) {          try {              concurrency();          } catch (InterruptedException e) {              e.printStackTrace();          }          serial();      }      private static void concurrency() throws InterruptedException {          long start = System.currentTimeMillis();          Thread thread = new Thread(new Runnable() {              @Override              public void run() {                   int a = 0;                   for (long i = 0; i < count; i++)                   {                       a += 5;                   }              }          });          thread.start();          int b = 0;          for (long i = 0; i < count; i++) {              b--;         }          thread.join();          long time = System.currentTimeMillis() - start;          System.out.println("concurrency : " + time + "ms,文弄b=" + b);      }      private static void serial() {          long start = System.currentTimeMillis();          int a = 0;          for (long i = 0; i < count; i++)          {              a += 5;          }          int b = 0;          for (long i = 0; i < count; i++) {              b--;         }          long time = System.currentTimeMillis() - start;          System.out.println("serial : " + time + "ms,b=" + b);      }  }  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.
copyright © 2025 powered by 编程之道  滇ICP备2023006006号-34sitemap