`
liuzhaomin
  • 浏览: 198768 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论
文章列表
    package com.ls.java.newio; import java.nio.ByteBuffer; public class TestSlice { public static void main(String[] args) { ByteBuffer buffer = ByteBuffer.allocate(10); for(int i=0; i<buffer.capacity(); ++i) buffer.put((byte) i); buffer.position(0); buffer.limit(buff ...
  package com.ls.java.newio; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.nio.charset.Charset; public class BaiduReader { private Charset charset = Charset.forName("GBK"); privat ...
  package com.ls.java.newio; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class CopyFile { public static void main(String[] a ...
  /**A synchronizer that may be exclusively owned by a thread. This * class provides a basis for creating locks and related synchronizers * that may entail a notion of ownership. The * AbstractOwnableSynchronizer class itself does not manage or * use this information. However, subclasses a ...
  /** * The thread running task. When nulled after set/cancel, this * indicates that the results are accessible. Must be * volatile, to ensure visibility upon completion. */ private volatile Thread runner; void innerRun() { if (!compa ...
    package com.ls.java_concurrency.countdownlatch; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.co ...
package com.ls.java_concurrency.countdownlatch; import java.util.concurrent.CountDownLatch; /** * The first is a start signal that prevents any worker from proceeding * until the driver is ready for them to proceed; * The second is a completion signal that allows the driver to wait * un ...
  package com.ls.java_concurrency.threadpoolexecutor; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; import java.u ...
/** *比较并更新对象的某一个整数类型的域 *@param obj 被操作的对象 *@param fieldoffset 被操作的域在对象中的偏移量 *@param expect 域的期望值 *@param update 域的更新值 */ boolean compareAndSwapInt(Object obj,long fieldoffset, int expect, int update); /** *比较并更新对象的某一个对象类型的域 *@param obj 被操作的对象 *@param fieldoffset 被操作的域在对象中的 ...
  /** *The basic strategy is to subdivide the table among Segments, *each of which itself is a concurrently readable hash table. */ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V>, Serializable { /** * The default in ...
TreeMap是基于红黑树实现的,无容量限制; TreeMap是非线程安全的;   public V put(K key, V value) { Entry<K,V> t = root; if (t == null) { // TBD: // 5045147: (coll) Adding null to an empty TreeSet should // throw NullPointerException // // compare(key, key); // type chec ...
  /** * Offloaded version of put for null keys */ private V putForNullKey(V value) { for (Entry<K,V> e = table[0]; e != null; e = e.next) { if (e.key == null) { V oldValue = e.value; e.value = value; e.re ...
  static class Entry<K,V> implements Map.Entry<K,V> { final K key; V value; Entry<K,V> next; final int hash; /** * Creates new entry. */ Entry(int h, K k, V v, Entry<K,V> n) { value = v; ...
  public HashMap(int initialCapacity, float loadFactor) { if (initialCapacity < 0) throw new IllegalArgumentException("Illegal initial capacity: " + initialCapacity); if (initialCapacity > MAXIMUM_CAPACITY ...
HashMap采用数组方式存储key,value构成的Entry,无容量限制; HashMap基于key hash寻找entry对象存放到数组的位置,对于hash冲突采用链表的方式来解决; HashMap在插入元素时可能会要扩大数组的容量,在扩大容量时要重新计算hash,并复制对象到新的数组中; HashMap是非线程安全的; 写道 Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and pe ...
Global site tag (gtag.js) - Google Analytics