ReadWriteLock in Java

A ReadWriteLock interface is more sophisticated than the Lock interface. Imagine you have an application that reads from and writes to some resource, but reading frequency is much more higher than writing frequency. Two or more threads reading the same resource do not cause any problem for each other, i.e., multiple threads reading the same […]

Read More

ReentrantLock in Java

A Reentrant lock is an implementation of java.util.concurrent.Lock interface with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities. Lock is acquired by lock() method and held by Thread until a call to unlock() method. ReentrantLock provides same visibility and ordering guarantee, provided […]

Read More

Lock in Java

We are already aware of basic concepts around thread synchronization and various mechanisms using synchronized keyword. A lock interface is a thread synchronization aid like synchronized block except lock can be used in a more sophisticated way than Java’s synchronized blocks. A lock is a tool for controlling access to a shared resource by multiple […]

Read More

Copy Constructor in Java

What is Copy Constructor Sometimes a programmer wants to create an exact but separate copy of an existing object so that subsequent changes to the copy should not alter the original or vice versa. This is made possible using the copy constructor. A copy constructor is a constructor that creates a new object using an […]

Read More

TreeSet in Java

What is TreeSet A NavigableSet implementation based on a TreeMap. The elements are ordered using their natural ordering, or by a Comparator provided at set creation time, depending on which constructor is used. Like HashSet, TreeSet also implements Set interface. Like HashSet, TreeSet allows to store only unique elements in their objects. HashSet is much […]

Read More

HashSet in Java

What is HashSet HashSet extends AbstractSet and is an implementation of Set interface. HashSet also implements Serializable and Cloneable interfaces. HashSet is backed by hash table(actually HashMap instance), i.e., the HashSet uses hash table(HashMap) to store collection elements. Like HashMap, it allows null only one element.

Read More

CopyOnWriteArrayList in Java

What is CopyOnWriteArrayList CopyOnWriteArrayList is a concurrent Collection class introduced in Java 5 Concurrent API. It implements List interface like ArrayList, Vector and LinkedList but it is a thread-safe collection and it achieves its thread-safety in a slightly different way than Vector or other thread-safe collection class. CopyOnWriteArrayList creates a fresh copy of the underlying […]

Read More

JUnit Code Coverage

JaCoCo is quite a new maven plug-in that provides the JaCoCo runtime agent to your tests and allows basic report creation. Currently it supports instruction, branch, line, method and class coverage which is pretty enough you can expect from this kind of tool. Additionally, it can measure and report cyclomatic complexity for methods and summarize […]

Read More

TreeMap in Java

What is TreeMap It is a Red-Black tree based NavigableMap implementation. Like HashMap it contains only unique elements. Unlike HashMap it cannot have null key but like HashMap it can have multiple null values. The map is sorted according to the natural ordering (ascending order) of its keys, or by a Comparator provided at map […]

Read More

1 2 3 22