Difference between ReentrantLock and Synchronized in Java
From Java 5 new lock implementations have been provided like ReentrantLock, ReentrantReadWriteLock which provide more extensive locking operations than can be obtained using synchronized methods and...
View ArticleExchanger in Java concurrency
Exchanger is one of the Synchronization class added along with other synchronization classes like CyclicBarrier, CountDownLatch, Semaphore and Phaser in java.util.concurrent package. How does Exchanger...
View ArticleHow to sort an ArrayList in descending order
When you add elements to an ArrayList, elements are added in sequential order and while iterating an arraylist same sequential order will be used. But sometimes we do have a requirement to sort an...
View ArticleReentrantReadWriteLock in Java
Even in a multi-threading application multiple reads can occur simultaneously for a shared resource. It is only when multiple writes happen simultaneously or intermix of read and write that there is a...
View ArticleHow to read file from the last line in Java
There are applications where you have to read huge files line by line may be using some tool like Pentaho, Camel. Let's say these files are in the format header, records and footer and you need to...
View ArticleSemaphore in Java Concurrency
Semaphore is one of the synchronization aid provided by java concurrency util in Java 5 along with other synchronization aids like CountDownLatch, CyclicBarrier, Phaser and Exchanger.The Semaphore...
View ArticleBlockingQueue in Java Concurrency
BlockingQueue, an interface is added in Java 5 with in the java.util.concurrent package which provides many other concurrent utilities like CyclicBarrier, Phaser, ConcurrentHashMapa, ReentranctLock...
View ArticleArrayBlockingQueue in Java Concurrency
ArrayBlockingQueue which is an implementation of the BlockingQueue interface was added in Java 5 along with other concurrent utilities like CopyOnWriteArrayList, ReentrantReadWriteLock, Exchanger,...
View ArticleHow to add double quotes to a String in Java
You may come across a scenario when you would want to add double quotes to a String, but Java uses double quotes while initializing a String so it won't recognize that double quotes should be added...
View ArticleDifference between HashMap and ConcurrentHashMap in Java
ConcurrentHashMap was added in Java 5 as an alternative for HashTable to improve the performance of the (key, value) pair kind of data structure while still keeping it thread safe. On the other hand...
View ArticleInjecting prototype bean in singleton bean in Spring
If we go by the definition of the singleton and prototype beans, it says - Singleton scope - Only one shared instance of a singleton bean is managed by the container, and all requests for beans with an...
View ArticleDifferent bean scopes in Spring
When you create a bean definition, you provide a configuration for creating actual instances of the class defined by that bean definition. By providing bean definition you can control not only, the...
View Articlestatic block in Java
Static block is used for static initializations of a class. Consider the scenario when initialization of static variables requires some logic (for example, error handling or a for loop to fill a...
View ArticleInitializer block in Java
If you want to initialize an instance variable you will put that code in a constructor. There is one alternative to using a constructor to initialize instance variables which is called initializer...
View ArticleCopyOnWriteArraySet in Java Concurrency
In Java 5 many concurrent collection classes are added as a thread safe alternative for their normal collection counterpart which are not thread safe. Like ConcurrentHashMap as a thread safe...
View ArticleDifference between ArrayList and CopyOnWriteArrayList in Java
CopyOnWriteArrayList was added in Java 5 as a thread-safe alternative to ArrayList, which is one of the most used collection along with HashMap.In this post we'll see the difference between the...
View ArticleSpring bean life cycle
Lifecycle of a bean in a Spring is quite elaborate and provides many callback methods to customize the nature of the bean. On the basis of functionality, these callback methods provide, you can...
View ArticleConcurrentSkipListMap in Java
ConcurrentSkipListMap is a scalable concurrent map which implements ConcurrentNavigableMapinterface. Though concurrent collections like ConcurrentHashMap and CopyOnWriteArrayList were added in Java...
View ArticleConcurrentSkipListSet in Java
ConcurrentSkipListSet is a scalable concurrent set which uses ConcurrentSkipListMap internally. Though concurrent collections like ConcurrentHashMap and CopyOnWriteArraySet were added in Java 1.5,...
View ArticleLinkedBlockingQueue in Java
LinkedBlockingQueue which is an implementation of BlockingQueue interface is added in Java 5 along with other concurrent utilities like CyclicBarrier, Phaser, ConcurentHashMap, CopyOnWriteArraySet...
View Article