Tag Archives: thread

Runnable Vs Callable in java

Well, this is one of the important interview question to check whether candidate aware about the multi-threading basic things or not. This is one of the interesting question too. And you can say it’s very popular interview question in various Java Interviews in all level.
The Callable interface is newer than Runnable interface and added on JDK 5 release. You know , there are major release of JDK 5 in which a lot of new things introduced e.g. Generics collection, Enum, Static imports and variable argument method etc. Although both Callable and Runnable interface are designed to represent a task, which can be executed by any thread.
Continue reading Runnable Vs Callable in java

How to Print Odd and Even Number by Thread using Semaphore

Oracle Java
We know order of running of two different thread is not in our hand by default but somewhere we need to control the order of running. So I tried to demonstrate inter thread communication by using Semaphore. This Java program prints odd & even numbers in sequential fashion using two different threads. It means one thread generates odd numbers and another thread generate even numbers.
Continue reading How to Print Odd and Even Number by Thread using Semaphore

Theads Deadlock Example in Java

Deadlock describes a situation where two or more threads are blocked forever, waiting for each other. You know , order of execution of threads are non-deterministic, so sometimes very difficult to reproduced deadlock situation , sometimes very hard to come out of deadlock situation, so be careful while locking order on multiple object by multiple threads.

Continue reading Theads Deadlock Example in Java