{"id":247,"date":"2016-12-26T17:54:37","date_gmt":"2016-12-26T09:54:37","guid":{"rendered":"http:\/\/www.prayerlaputa.com\/?p=247"},"modified":"2016-12-26T17:54:37","modified_gmt":"2016-12-26T09:54:37","slug":"%e3%80%90%e6%ba%90%e7%a0%81%e5%88%86%e6%9e%90%e3%80%91java%e7%af%87-concurrentskiplistmap","status":"publish","type":"post","link":"http:\/\/prayerlaputa.com\/?p=247","title":{"rendered":"\u3010\u6e90\u7801\u5206\u6790\u3011java sdk\u7bc7&#8211;ConcurrentSkipListMap"},"content":{"rendered":"<p>\u6700\u8fd1\u5f00\u59cb\u770bjdk\u6e90\u4ee3\u7801\uff0c\u5148\u5206\u4eab\u4e00\u4e2a\u633a\u597d\u7684\u535a\u5ba2\uff1a<a href=\"http:\/\/blog.csdn.net\/chenssy\">http:\/\/blog.csdn.net\/chenssy<\/a>\u00a0 chenssy \u6709\u5173JDK\u6e90\u7801\u7684\u535a\u6587\u5199\u7684\u5f88\u7ec6\uff0c\u6211\u5c31\u53c2\u8003\u4ed6\u7684\u535a\u6587\u5199\u5199\u5176\u4ed6\u7684\u5185\u5bb9\uff0c\u5df2\u7ecf\u88abchenssy\u5199\u8fc7\u7684\u5185\u5bb9\u6211\u5c31\u4e0d\u518d\u91cd\u590d\u5566\uff0c\u4f30\u8ba1\u4e5f\u6ca1\u4ed6\u5199\u7684\u7ec6\u3002\u53e6\u5916\uff0c\u5982\u679c\u7f51\u4e0a\u5df2\u6709\u76f8\u5173\u5206\u6790\uff0c\u6211\u53ef\u80fd\u76f4\u63a5\u7ed9\u51fa\u94fe\u63a5\u3001\u505a\u505a\u8865\u5145\uff0c\u6bd5\u7adf\u672c\u7cfb\u5217\u5c5e\u4e8e\u8bfb\u4e66\u7b14\u8bb0\u6027\u8d28\uff0c\u7559\u4e0b\u4e2a\u8bb0\u5f55\u514d\u5f97\u81ea\u5df1\u5fd8\u8bb0\uff0c\u5e76\u4e0d\u6253\u7b97\u5199\u7684\u7279\u522b\u5168\u6216\u662f\u5168\u90e8\u539f\u521b\u3002\u4e0b\u9762\u5c31\u5f00\u59cb\u3010\u6e90\u7801\u5206\u6790\u3011\u7cfb\u5217\u7684\u7b2c\u4e00\u7bc7\uff1aConcurrentSkipListMap<br \/>\n\u58f0\u660e\uff1a\u672c\u535a\u5ba2\u5185\u5bb9\u4e00\u822c\u91c7\u96c6\u81ea\u4e92\u8054\u7f51\uff0c\u82e5\u5f15\u7528\u4e86\u5176\u4ed6\u6587\u7ae0\u6216\u662f\u535a\u5ba2\u7684\u5185\u5bb9\uff0c\u6211\u4f1a\u5c3d\u91cf\u6ce8\u660e\u51fa\u5904\u3002\u5982\u679c\u6709\u8f6c\u8f7d\u3001\u672a\u6ce8\u660e\u51fa\u5904\uff0c\u6216\u662f\u6709\u4fb5\u6743\u7684\u60c5\u51b5\uff0c\u8bf7\u53ca\u65f6\u4e0e\u6211\u6c9f\u901a\uff08evasnowind@sina.com\uff09\uff0c\u6211\u4f1a\u53ca\u65f6\u5220\u9664\u3002\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u672c\u6587\u51fa\u5904\uff0c\u8c22\u8c22\u3002<br \/>\n\u5728java\u4e2d\uff0c<br \/>\n\u5982\u679c\u6211\u4eec\u9700\u8981\u5feb\u901f\u5b58\u53d6\u952e\u503c\u5bf9\uff0c\u53ef\u4ee5\u7528HashMap\uff1b<!--more--><br \/>\n\u5982\u679c\u8981\u6c42\u591a\u7ebf\u7a0b\u5e76\u53d1\u5b58\u53d6\u952e\u503c\u5bf9\uff0c\u53ef\u4ee5\u7528ConcurrentHashMap\uff1b<br \/>\n\u5982\u679c\u8981\u6c42\u5feb\u901f\u5b58\u53d6\u952e\u503c\u5bf9\uff0c\u5e76\u8981\u6c42\u952e\u503c\u5bf9\u6309\u7167\u67d0\u79cd\u987a\u5e8f\u6392\u5e8f\uff0c\u53ef\u4ee5\u7528TreeMap\uff1b<br \/>\n\u5982\u679c\uff0c\u6211\u4eec\u9700\u8981\u5feb\u901f\u5b58\u53d6\u952e\u503c\u5bf9\uff0c\u652f\u6301\u591a\u7ebf\u7a0b\u5e76\u53d1\u5b58\u53d6\uff0c\u8fd8\u8981\u6c42\u6570\u636e\u6709\u5e8f\uff0c\u662f\u5426\u6709\u73b0\u6210\u7684\u6570\u636e\u7ed3\u6784\uff1f<br \/>\n\u7b54\u6848\u662f\u80af\u5b9a\uff0c\u90a3\u5c31\u662fConcurrentSkipListMap\u3002<\/p>\n<h2>\u4e00\u3001\u6982\u8ff0<\/h2>\n<p><strong>JDK 1.6<\/strong>\u4e2d\u5f15\u5165\u4e86ConcurrentSkipListMap\u8fd9\u4e00\u6570\u636e\u7ed3\u6784\uff0cJDK\u6587\u6863\u63cf\u8ff0\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>A scalable concurrent <code><a href=\"eclipse-javadoc:%E2%98%82=HMSExample\/D:%5C\/DevTools%5C\/android-sdk-windows%5C\/platforms%5C\/android-23%5C\/android.jar%3Cjava.util.concurrent(ConcurrentSkipListMap.class%E2%98%83ConcurrentSkipListMap%E2%98%82ConcurrentNavigableMap\">ConcurrentNavigableMap<\/a><\/code> implementation. The map is sorted according to the <a href=\"eclipse-javadoc:%E2%98%82=HMSExample\/D:%5C\/DevTools%5C\/android-sdk-windows%5C\/platforms%5C\/android-23%5C\/android.jar%3Cjava.util.concurrent(ConcurrentSkipListMap.class%E2%98%83ConcurrentSkipListMap%E2%98%82Comparable\">natural ordering<\/a> of its keys, or by a <code><a href=\"eclipse-javadoc:%E2%98%82=HMSExample\/D:%5C\/DevTools%5C\/android-sdk-windows%5C\/platforms%5C\/android-23%5C\/android.jar%3Cjava.util.concurrent(ConcurrentSkipListMap.class%E2%98%83ConcurrentSkipListMap%E2%98%82Comparator\">Comparator<\/a><\/code> provided at map creation time, depending on which constructor is used.<br \/>\nThis class implements a concurrent variant of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Skip_list\" target=\"_top\" rel=\"noopener noreferrer\">SkipLists<\/a> providing expected average <i>log(n)<\/i> time cost for the <code>containsKey<\/code>, <code>get<\/code>, <code>put<\/code> and <code>remove<\/code> operations and their variants. Insertion, removal, update, and access operations safely execute concurrently by multiple threads. Iterators are <i>weakly consistent<\/i>, returning elements reflecting the state of the map at some point at or since the creation of the iterator. They do <em>not<\/em> throw <code><a href=\"eclipse-javadoc:%E2%98%82=HMSExample\/D:%5C\/DevTools%5C\/android-sdk-windows%5C\/platforms%5C\/android-23%5C\/android.jar%3Cjava.util.concurrent(ConcurrentSkipListMap.class%E2%98%83ConcurrentSkipListMap%E2%98%82ConcurrentModificationException\">ConcurrentModificationException<\/a><\/code>, and may proceed concurrently with other operations. Ascending key ordered views and their iterators are faster than descending ones.<br \/>\nAll <code>Map.Entry<\/code> pairs returned by methods in this class and its views represent snapshots of mappings at the time they were produced. They do <em>not<\/em> support the <code>Entry.setValue<\/code> method. (Note however that it is possible to change mappings in the associated map using <code>put<\/code>, <code>putIfAbsent<\/code>, or <code>replace<\/code>, depending on exactly which effect you need.)<br \/>\nBeware that, unlike in most collections, the <code>size<\/code> method is <em>not<\/em> a constant-time operation. Because of the asynchronous nature of these maps, determining the current number of elements requires a traversal of the elements, and so may report inaccurate results if this collection is modified during traversal. Additionally, the bulk operations <code>putAll<\/code>, <code>equals<\/code>, <code>toArray<\/code>, <code>containsValue<\/code>, and <code>clear<\/code> are <em>not<\/em> guaranteed to be performed atomically. For example, an iterator operating concurrently with a <code>putAll<\/code> operation might view only some of the added elements.<br \/>\nThis class and its views and iterators implement all of the <em>optional<\/em> methods of the <code><a href=\"eclipse-javadoc:%E2%98%82=HMSExample\/D:%5C\/DevTools%5C\/android-sdk-windows%5C\/platforms%5C\/android-23%5C\/android.jar%3Cjava.util.concurrent(ConcurrentSkipListMap.class%E2%98%83ConcurrentSkipListMap%E2%98%82Map\">Map<\/a><\/code> and <code><a href=\"eclipse-javadoc:%E2%98%82=HMSExample\/D:%5C\/DevTools%5C\/android-sdk-windows%5C\/platforms%5C\/android-23%5C\/android.jar%3Cjava.util.concurrent(ConcurrentSkipListMap.class%E2%98%83ConcurrentSkipListMap%E2%98%82Iterator\">Iterator<\/a><\/code> interfaces. Like most other concurrent collections, this class does <em>not<\/em> permit the use of <code>null<\/code> keys or values because some null return values cannot be reliably distinguished from the absence of elements.<\/p><\/blockquote>\n<p>\u7b80\u5355\u6982\u62ec\u4e0b\u5173\u952e\u70b9\uff1a<\/p>\n<ul>\n<li>\u5e38\u7528\u64cd\u4f5c\uff0c\u5982containsKey\/get\/put\/remove\/..\uff0c\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a<i>log(n)<\/i><\/li>\n<li>CURD\u7b49\u64cd\u4f5c\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u53ef\u4ee5\u88ab\u591a\u4e2a\u7ebf\u7a0b\u5e76\u53d1\u6267\u884c<\/li>\n<li>Iterator\u662f\u5f31\u4e00\u81f4\u7684<\/li>\n<li>Map.Entry\u53cd\u6620\u7684\u662fEntry\u88ab\u521b\u5efa\u65f6\u7684\u6570\u636e\uff08\u6211\u4e2a\u4eba\u7406\u89e3\uff1a\u7531\u4e8e\u652f\u6301\u591a\u7ebf\u7a0b\uff0cEntry\u88ab\u521b\u5efa\u540eMap\u7684\u6570\u636e\u53ef\u80fd\u4f1a\u6539\u53d8\uff09\uff0c\u4e0d\u652f\u6301Entry.setValue\u65b9\u6cd5<\/li>\n<li>size()\u65b9\u6cd5\u4e0d\u662f\u4e00\u4e2a\u5e38\u91cf\u65f6\u95f4\u64cd\u4f5c\uff0c\u6bcf\u6b21\u8c03\u7528\u90fd\u4f1a\u8fdb\u884c\u4e00\u6b21\u904d\u5386\u6765\u8ba1\u7b97\u5f53\u524dMap\u5185\u5143\u7d20\u7684\u4e2a\u6570<\/li>\n<li><code>putAll<\/code>, <code>equals<\/code>, <code>toArray<\/code>, <code>containsValue<\/code>, and <code>clear\u8fd9\u4e9b\u65b9\u6cd5\u5e76\u4e0d\u662f\u539f\u5b50\u6027\u7684\u64cd\u4f5c<\/code><\/li>\n<li>key\u548cvalue\u90fd\u4e0d\u80fd\u662fnull<\/li>\n<\/ul>\n<h2>\u4e8c\u3001\u4f7f\u7528\u5efa\u8bae<\/h2>\n<blockquote><p>\u5728\u975e\u591a\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\uff0c\u5e94\u5f53\u5c3d\u91cf\u4f7f\u7528TreeMap\u3002\u6b64\u5916\u5bf9\u4e8e\u5e76\u53d1\u6027\u76f8\u5bf9\u8f83\u4f4e\u7684\u5e76\u884c\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528Collections.synchronizedSortedMap\u5c06TreeMap\u8fdb\u884c\u5305\u88c5\uff0c\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u8f83\u597d\u7684\u6548\u7387\u3002\u5bf9\u4e8e\u9ad8\u5e76\u53d1\u7a0b\u5e8f\uff0c\u5e94\u5f53\u4f7f\u7528ConcurrentSkipListMap\uff0c\u80fd\u591f\u63d0\u4f9b\u66f4\u9ad8\u7684\u5e76\u53d1\u5ea6\u3002<br \/>\n\u6240\u4ee5\u5728\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u4e2d\uff0c\u5982\u679c\u9700\u8981\u5bf9Map\u7684\u952e\u503c\u8fdb\u884c\u6392\u5e8f\u65f6\uff0c\u8bf7\u5c3d\u91cf\u4f7f\u7528ConcurrentSkipListMap\uff0c\u53ef\u80fd\u5f97\u5230\u66f4\u597d\u7684\u5e76\u53d1\u5ea6\u3002<br \/>\n\u6ce8\u610f\uff0c\u8c03\u7528ConcurrentSkipListMap\u7684size\u65f6\uff0c\u7531\u4e8e\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u5bf9\u6620\u5c04\u8868\u8fdb\u884c\u64cd\u4f5c\uff0c\u6240\u4ee5\u6620\u5c04\u8868\u9700\u8981\u904d\u5386\u6574\u4e2a\u94fe\u8868\u624d\u80fd\u8fd4\u56de\u5143\u7d20\u4e2a\u6570\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u662f\u4e2aO(log(n))\u7684\u64cd\u4f5c\u3002<br \/>\n\u5f15\u81ea\uff1a<a href=\"http:\/\/www.2cto.com\/kf\/201212\/175026.html\">Java\u591a\u7ebf\u7a0b\uff08\u56db\uff09\u4e4bConcurrentSkipListMap\u6df1\u5165\u5206\u6790<\/a><\/p><\/blockquote>\n<h2>\u4e09\u3001\u4ee3\u7801\u5206\u6790<\/h2>\n<p>ConcurrentSkipListMap\u5185\u90e8\u5b9e\u73b0\u91c7\u7528\u4e86\u8df3\u8dc3\u8868\uff0c\u6709\u5173\u8df3\u8dc3\u8868\u7684\u5206\u6790\u53c2\u89c1\uff1a<a href=\"http:\/\/kenby.iteye.com\/blog\/1187303\">SkipList \u8df3\u8868<\/a><br \/>\n\u6709\u5173\u66f4\u8be6\u7ec6\u7684\u5206\u6790\u53c2\u89c1\uff1a<br \/>\n<a href=\"http:\/\/blog.csdn.net\/sunxianghuang\/article\/details\/52221913\">\u8df3\u8868\uff08SkipList\uff09\u53caConcurrentSkipListMap\u6e90\u7801\u89e3\u6790<\/a><br \/>\n<a href=\"http:\/\/www.cnblogs.com\/skywang12345\/p\/3498556.html\">Java\u591a\u7ebf\u7a0b\u7cfb\u5217&#8211;\u201cJUC\u96c6\u5408\u201d05\u4e4b ConcurrentSkipListMap<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5f00\u59cb\u770bjdk\u6e90\u4ee3\u7801\uff0c\u5148\u5206\u4eab\u4e00\u4e2a\u633a\u597d\u7684\u535a\u5ba2\uff1ahttp:\/\/blog.csdn.net\/chenssy\u00a0 ch <a href='http:\/\/prayerlaputa.com\/?p=247' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[6,18,19],"tags":[33,50,51],"_links":{"self":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/247"}],"collection":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=247"}],"version-history":[{"count":0,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/247\/revisions"}],"wp:attachment":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}