Posts

Avoid Deadlock in Java

Image
  Java programming language supports multithreading. It involves multiple threads running simultaneously for multitasking. But in certain cases or due to certain shortcomings, the threads find themselves in the waiting state forever. In this article, We will understand the deadlock condition in Java and different ways to avoid it. The following are the topics discussed in this article: What is Deadlock in Java? Deadlock Example How To Avoid Deadlock in Java? What is Deadlock in Java? Deadlock in Java is a condition where two or more threads are blocked forever, waiting for each other. This usually happens when multiple threads need the same locks but obtain them in different orders. Multithreaded Programming in Java suffers from the deadlock situation because of the synchronized keyword. It causes the executing thread to block while waiting for the lock, or monitor, associated with the specified object. Deadlock Example public class Example { public static void main(String[] arg...

Java 8 Stream API

  Introduced in   Java 8   along with other programming features,   Stream API   provides various functionalities to process a collection of objects. Before we dive into Streams API, let’s see for an example, how we used to iterate a List and calculate the sum before the introduction of Streams in Java 8. List<Integer> numList = Arrays.asList(2,5,7,9,10,20,30,40); int sum = 0; Iterator<Integer> iterator = numList.iterator(); while (iterator.hasNext()) { int number = iterator.next(); if (number< 10) { sum += number; } } The above codes works perfectly fine and the variable sum will have the value 23 as the sum of numbers less than 10, but there are few issues with this code. The code has to be written on how the list should be iterated although the requirement is just to obtain the sum of the numbers which are less than 10 The program is sequential A lot of code must be written to perform this simple calculation. To avoid the above ...

The TRUE difference between [] and {{}} bindings in Angular

  One of the parts of Angular that most developers think they understand, but many don’t, is the true nature of [] and {{}} bindings. A fundamental lack of understanding of these bindings can become a major issue when working with templates and trying to get them to do exactly what you want. It can also be the cause of spending an unnecessary amount of hours trying to figure out a bug. So I’m going to run down exactly what these two bindings do, and what it is that many developers misunderstand about them. You’re probably familiar with the typical usage of {{}} bindings: <h1>{{title}}</h1> And you’re probably familiar with the typical usage of [] or property bindings: <img [src]="imgsrc"> But do you truly understand what each binding is doing? And why we use them in this situation? Many if not most developers simply know to use {{}} when putting text in an element, and [] for binding to properties. But have you ever wondered with reactive forms why the  form...

Use @Initbinder in Spring MVC

Image
In this blog we will learn how to use @initbinder Annotation in Spring MVC. We will walk through a small example with help of a demo application. If you’re familiar with MVC architecture ,you must all be aware that controller is used for processing the web request and rendering the response to the View. Now,Initbinder comes into picture if you want to customize the request being sent to the controller.It is defined in the controller, helps in controlling and formatting each and every request that comes to it. This annotation is used with the methods which initializes  WebDataBinder  and works as a preprocessor for each request coming to the controller. InitBinder interaction with other Components Seems lot of gyaan right ! So,now to explain this let’s take an example. Consider we have student management portal for a school ,which manages the information of all the students present in the school.It has a feature for registering a student when he is admitted to the school. ...