Category Archives: Concurrency

Inter thread communication in java (Example/ PipedInputStream /PipedOutputStream)

Inter thread communication is very common phenomenon. There are many ways to achieve inter thread communication. In current post, we will use pipes to achieve thread communication. Java has set of classes named PipedOutputStream & PipedInputStream to communicate between threads. We will create couple of threaders namely producer & consumer. Producer thread will produce the… Read More »

Thread join example using Runnable interface in java

Create a task by implementing Runnable interface. We will demonstrate join method and its impact on execution on multiple threads. We will write couple of methods demoThreadJoin: Method will create multiple threads. Output of a method will demonstrates the execution of join method. Threads will execute one after another (i.e. thread-1 to thread-4). demoWithoutThreadJoin: Method… Read More »

Create or simulate deadlock in java (multithreading & example)

What is deadlock? The deadlock is the situation, which occurs when one thread is waiting for the resource, which has been acquired by second thread and second thread is waiting for the resource which has been acquired by first thread. This cyclic dependency results in a deadlock situation. Example of deadlock situation in java Suppose, we… Read More »

Create runnable task using functional interface – java8 lambda stream (example)

1. Functional Interface java 8: The interface having one abstract method is called the functional interface. E.g. Comparator, Runnable interface. The runnable interface will look like as follows @FunctionalInterface public interface Runnable { public abstract void run(); } We have discussed about the Creating threads using runnable interface. In current post we will see how… Read More »

Page 1 of 212