CyclicBarrier class

Intro to CyclicBarrier class in Java First we will take an example, after that we will understand immediately what the CyclicBarrier does. Now, say we have three tasks, and there are two officers, each officer will do those three tasks in order: task 1, task 2 and task 3, in each one’s own thread. So…

ExecutorService interface

Introduction to ExecutorService interface ExecutorService is an interface, we create its instance by static factory method. But first we have to import the concurrent package: Here is a small example. Again we use the simple Runnable example: Ok, nothing special here. execute method   Next, to create an instance of ExecutorService, we don’t use the new…

Java Test 42

Java Test for Object Monitor Don’t try to hack or to do something unusual, this is just some basic Java tests for object monitor, to see what we learned until now. Please try to finish these tests without using an IDE. After choosing your options (radio buttons) please press Check button to see the result….

Java Test 41

Java Test for Multithreading Don’t try to hack or to do something unusual, this is just some basic Java tests for multithreading, to see what we learned until now. Please try to finish these tests without using an IDE. After choosing your options (radio buttons) please press Check button to see the result. Note that…

Runnable interface

Runnable interface The problem with the Thread class is that a class in Java can only extend a maximum of one other class. So if our MyThread class extends Thread class, it cannot extend any other class. To meet that real demand, Java provides the Runnable interface, the Runnable interface has only one abstract class,…