In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the usage of BitCaskKeyDir in java". In daily operation, I believe many people have doubts about the usage of BitCaskKeyDir in java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about the usage of BitCaskKeyDir in java! Next, please follow the editor to study!
Order
This paper mainly studies BitCaskKeyDir.
BitCaskKeyDir
Bitcask-java/src/main/java/com/trifork/bitcask/BitCaskKeyDir.java
Public class BitCaskKeyDir {Map map = new HashMap (); ReadWriteLock rwl = new ReentrantReadWriteLock (); private boolean is_ready; public boolean put (ByteString key, BitCaskEntry ent) {Lock writeLock = rwl.writeLock (); writeLock.lock (); try {BitCaskEntry old = map.get (key) If (old = = null) {map.put (key, ent); return true;} else if (ent.is_newer_than (old)) {map.put (key, ent) Return true;} else {return false;}} finally {writeLock.unlock () }} public BitCaskEntry get (ByteString key) {Lock readLock = rwl.readLock (); readLock.lock (); try {return map.get (key) } finally {readLock.unlock ();}} /.}
BitCaskKeyDir provides map to store BitCaskEntry; and its put method uses writeLock.lock (). If the null value is null or the new value is greater than the Old value, the put goes in, otherwise it returns false, and finally writeLock.unlock (); its get method uses readLock.lock () to read the value of the specified key from map, and finally readLock.unlock ()
Key_dirs
Bitcask-java/src/main/java/com/trifork/bitcask/BitCaskKeyDir.java
Public class BitCaskKeyDir {public static Map key_dirs = new HashMap (); public static Lock keydir_lock = new ReentrantLock (); public static BitCaskKeyDir keydir_new (File dirname, int openTimeoutSecs) throws IOException {File abs_name = dirname.getAbsoluteFile (); BitCaskKeyDir dir; keydir_lock.lock () Try {dir = key_dirs.get (abs_name); if (dir = = null) {dir = new BitCaskKeyDir (); key_dirs.put (abs_name, dir) Return dir;}} finally {keydir_lock.unlock () } if (dir.wait_for_ready (openTimeoutSecs)) {return dir;} else {throw new IOException ("timeout while waiting for keydir");}} public synchronized boolean is_ready () {return is_ready } public synchronized void mark_ready () {is_ready = true; this.notifyAll ();} public synchronized boolean wait_for_ready (int timeout_secs) {long now = System.currentTimeMillis (); long abs_timeout = now + (timeout_secs * 1000) While (! is_ready & & now < abs_timeout) {try {wait () } catch (InterruptedException e) {/ / ignore} now = System.currentTimeMillis ();} return is_ready;}}
BitCaskKeyDir defines the key_dirs of the static, which is used to store the BitCaskKeyDir; of the specified File. The keydir_new is created for the BitCaskKeyDir that does not exist, and finally waits for the ready via dir.wait_for_ready (openTimeoutSecs).
Summary
BitCaskKeyDir provides map to store BitCaskEntry; and its put method uses writeLock.lock (). If the null value is null or the new value is greater than the Old value, the put goes in, otherwise it returns false, and finally writeLock.unlock (); its get method uses readLock.lock () to read the value of the specified key from map, and finally readLock.unlock ()
At this point, the study of "the use of BitCaskKeyDir in java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.