{"id":2289,"date":"2017-11-01T17:29:50","date_gmt":"2017-11-01T09:29:50","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2289"},"modified":"2017-11-01T17:29:50","modified_gmt":"2017-11-01T09:29:50","slug":"%e9%ab%98%e5%b9%b6%e5%8f%91%e5%9c%ba%e6%99%af%e4%b8%8bsystem-currenttimemillis%e7%9a%84%e6%80%a7%e8%83%bd%e9%97%ae%e9%a2%98%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2289","title":{"rendered":"\u9ad8\u5e76\u53d1\u573a\u666f\u4e0bSystem.currentTimeMillis()\u7684\u6027\u80fd\u95ee\u9898\u4f18\u5316"},"content":{"rendered":"<p>\n\t\u4f60\u4e5f\u8bb8\u7528\u8fc7System.currentTimeMillis()\uff0c\u4f46\u662f\u4f60\u53ef\u80fd\u4e0d\u77e5\u9053\u5b83\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u3002\u4e4b\u524d\u7684\u6d4b\u8bd5\u6570\u636e\u5177\u4f53\u591a\u5c11\u6211\u5fd8\u8bb0\u4e86\uff0c\u4f46\u662f\u6211\u5927\u6982\u8bb0\u5f97System.currentTimeMillis()\u7684\u8c03\u7528\u6bd4new\u4e00\u4e2a\u666e\u901a\u5bf9\u8c61\u8981\u8017\u65f6\u7684\u591a\uff08\u5177\u4f53\u8017\u65f6\u9ad8\u51fa\u591a\u5c11\u6211\u8fd8\u6ca1\u6d4b\u8bd5\u8fc7\uff0c\u6709\u4eba\u8bf4\u662f100\u500d\u5de6\u53f3\uff09\u3002\u56e0\u6b64\u5728\u9ad8\u5e76\u53d1\u4e0b\uff0c\u5728\u9ad8\u9891\u7387\u4f7f\u7528System.currentTimeMillis()\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5f88\u6709\u5fc5\u8981\u5bf9System.currentTimeMillis()\u8fdb\u884c\u4e00\u6b21\u4f18\u5316\u3002\n<\/p>\n<p>\n\tSystem.currentTimeMillis()\u4e4b\u6240\u4ee5\u6162\u662f\u56e0\u4e3a\u53bb\u8ddf\u7cfb\u7edf\u6253\u4e86\u4e00\u6b21\u4ea4\u9053\u3002\u5177\u4f53\u9700\u8981\u4f60\u770b\u8fc7\u6e90\u7801\u624d\u77e5\u9053\u3002\n<\/p>\n<p>\n\t\u672c\u4f18\u5316\u5b9e\u73b0\u540e\u53f0\u5b9a\u65f6\u66f4\u65b0\u65f6\u949f\uff0cJVM\u9000\u51fa\u65f6\uff0c\u7ebf\u7a0b\u81ea\u52a8\u56de\u6536\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u662f\u76f8\u5173\u4f18\u5316\u7684\u5177\u4f53\u4ee3\u7801\uff1a\n<\/p>\n<pre class=\"brush:java;\">\r\npublic class SystemClock {\r\n\tprivate final long period;\r\n\tprivate final AtomicLong now;\r\n\t\/\/ \u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\n\tprivate SystemClock(long period) {\r\n\t\tthis.period = period;\r\n\t\tthis.now = new AtomicLong(System.currentTimeMillis());\r\n\t\tscheduleClockUpdating();\r\n\t}\r\n\tprivate static class InstanceHolder {\r\n\t\tpublic static final SystemClock INSTANCE = new SystemClock(1);\r\n\t}\r\n\tprivate static SystemClock instance() {\r\n\t\treturn InstanceHolder.INSTANCE;\r\n\t}\r\n\tprivate void scheduleClockUpdating() {\r\n\t\tScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {\r\n\t\t\tpublic Thread newThread(Runnable runnable) {\r\n\t\t\t\tThread thread = new Thread(runnable, &quot;System Clock&quot;);\r\n\t\t\t\tthread.setDaemon(true);\r\n\t\t\t\treturn thread;\r\n\t\t\t}\r\n\t\t});\r\n\t\tscheduler.scheduleAtFixedRate(new Runnable() {\r\n\t\t\tpublic void run() {\r\n\t\t\t\tnow.set(System.currentTimeMillis());\r\n\t\t\t}\r\n\t\t}, period, period, TimeUnit.MILLISECONDS);\r\n\t}\r\n\tprivate long currentTimeMillis() {\r\n\t\treturn now.get();\r\n\t}\r\n\tpublic static long now() {\r\n\t\treturn instance().currentTimeMillis();\r\n\t}\r\n\tpublic static String nowDate() {\r\n\t\treturn new Timestamp(instance().currentTimeMillis()).toString();\r\n\t}\r\n}<\/pre>\n<p>\n\t\u4e0b\u9762\u662f\u5927\u91cf\u6d4b\u8bd5\u540e\u5f97\u51fa\u7684\u7ed3\u679c\uff1a\n<\/p>\n<p>\n\t10\u4ebf\uff1a43410,206,210.72815533980582%<br \/>\n\t1\u4ebf\uff1a4699,29,162.0344827586207%<br \/>\n\t1000\u4e07\uff1a480,12,40.0%<br \/>\n\t100\u4e07\uff1a50,10,5.0%\n<\/p>\n<p>\n\t\u4ee5\u4e0a\u4e0a\u4e2a\u4ec5\u4f9b\u53c2\u8003\uff0c\u5177\u4f53\u548c\u4f60\u7684\u786c\u4ef6\u914d\u7f6e\u7b49\u6709\u5173\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2289\">\u9ad8\u5e76\u53d1\u573a\u666f\u4e0bSystem.currentTimeMillis()\u7684\u6027\u80fd\u95ee\u9898\u4f18\u5316<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u4f60\u4e5f\u8bb8\u7528\u8fc7System.currentTimeMillis()\uff0c\u4f46\u662f\u4f60\u53ef\u80fd\u4e0d\u77e5\u9053\u5b83\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u3002 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[69,106,502,505],"class_list":["post-2289","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","tag-106","tag-502","tag-505"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2289"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2289\/revisions"}],"predecessor-version":[{"id":2290,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2289\/revisions\/2290"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}