Learnitweb

Category: Java tutorial

  • Executor framework in Java – an introduction

    The executor framework is Java enables you to separate thread creation and management for the implementation of concurrent tasks. With executor framework, you don’t have to worry about creation and management of threads, only create tasks and submit to the executor. Let us see important classes and interfaces of executor framework. 1. Executor This is…

  • CyclicBarrier in Java

    1. Introduction The CyclicBarrier allows a set of threads to all wait for each other to reach a common barrier point. This class is similar to the CountDownLatch class but the barrier in this case is reusable after the waiting threads are released and hence the name cyclic. CyclicBarrier is used when there is a…

  • CountDownLatch in Java

    1. Introduction The Java concurrency API provides a CountDownLatch class that allows one or more threads to wait until a set of operations are done. CountDownLatch is initialized with an integer value (N). This count is the number of operations the threads are going to wait for. When a thread wants to wait for the…

  • Semaphore in Java

    1. Introduction The concept of a semaphore was introduced by Edsger Dijkstra in 1965 and was used for the first time in the THEOS operating system. The semaphore mechanism is used to control the access to one or more shared resources. The java.util.Semaphore class represents a counting semaphore which is initialized with a number of…

  • BlockingQueue in Java

    1. Introduction In this tutorial we’ll discuss BlockingQueue interface which is defined in java.util.concurrent package. BlockingQueue is a subinterface of java.util.Queue that also supports blocking operations that wait for the queue to become nonempty before retrieving an element and wait for space to become available in the queue before storing an element. BlockingQueue is typically…

  • Comparator in Java

    Comparator interface provides a way to control the sort order on some collection of objects. Comparator like Comparable interface imposes a total ordering on some collection of objects. Comparator can be used to control the order of certain data structures like sorted sets. Comparator can be used to provide an ordering for collections of objects…

  • Comparable in Java

    1. Introduction Comparable interface is provided in java.lang package. This interface is a part of Java Collections Framework. This interface imposes total ordering on the objects of the class which implements this interface. This ordering is referred to as the natural ordering. The Comparable interface provides a method compareTo which is referred as its natural…

  • hashCode method in Java

    1. Introduction In this tutorial, we’ll discuss what is hash code in Java and the hashCode() method provided in Object class. Hash code is one of the most important concepts of Java and used extensively in data structure implementations like HashMap. Whenever you want to override the custom behavior of few data structures provided by…

  • Thread interruption in Java

    1. Introduction A Java program with more than one thread finishes only when all non-daemon threads have finished execution or one of the threads call System.exit() method. Sometimes, you may need to terminate a thread when you want to cancel the task that the thread is doing. When there is such requirement, we can interrupt…

  • Generations and generational garbage collection in Java

    1. Introduction In this tutorial, we’ll discuss how garbage collector works. We’ll also discuss generations and generational garbage collection process. An object is considered to be eligible to be collected by garbage collector when it can no longer be reached from any reference of any live object in the running program. The memory of any…