Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Application exits when all daemon threads exit

Bipartite Graph

In this example we shall show you how to create a daemon thread in order to force an application to exit. We have created a class, MyDaemonThread that extends the Thread and overrides its run() method. In short: In its run() method the thread tests if it is a daemon thread, with isDaemon() API method of Thread and sleeps for one ...

Read More »

Daemon Thread example

Bipartite Graph

With this example we are going to demonstrate how to create a daemon Thread. We have implemented a class, MyDaemonThread, that implements the Runnable, as described below: The runnable creates a new Thread, marks it as a daemon, using setDaemon(boolean on) API method of Thread, and then begins the thread’s execution calling its start() API method. The class overrides the run() ...

Read More »

CyclicBarrier example

Bipartite Graph

This is an example of how to use a CyclicBarrier. A CyclicBarrier is a synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. CyclicBarriers are useful in programs involving a fixed sized party of threads that must occasionally wait for each other. The barrier is called cyclic because it ...

Read More »

CountDownLatch example

Bipartite Graph

In this example we shall show you how to use a CountDownLatch. The CountDownLatch is a synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes. A CountDownLatch is initialized with a given count. The await methods block until the current count reaches zero due to invocations of the countDown() ...

Read More »

Multiple access example

Bipartite Graph

With this example we are going to demonstrate how to have multiple access over an object. The example describes the transfer of amounts of bank accounts in a bank. In short: We have created a class named SwissBank. It has a double array called accounts, a Lock called bankLock and a Condition called sufficientFunds. It has a constructor in which for ...

Read More »

Return a value from a thread

Bipartite Graph

This is an example of how to return the value of a Thread. The steps of the example are described in short: We have implemented two classes, RetDouble and RetInt that both implement the Callable, the first using as parameter a Double and the second one using as parameter an Integer. They both override the call() method of the Callable, and ...

Read More »

Worker coordination using WorkQueue

Bipartite Graph

In this example we shall show you how to achieve a coordination between two threads that try to get the same objects. The steps of the example are described below: We have created a class, WorkerQueue, that has a LinkedList of Objects. In its synchronized void addWork(Object o) method it appends the object to the end of the list, with ...

Read More »

ThreadLocal example

Bipartite Graph

With this example we are going to demonstrate how to create a ThreadLocal. The ThreadLocal class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one has its own, independently initialized copy of the variable. ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread. In short, to create a ThreadLocal you ...

Read More »

Thread communication using Queue example

Bipartite Graph

This is an example of how to achieve a queue communication between two Threads. The example is described in short: We have created a class, PrepProduct that implements the Runnable and has a BlockingQueue of Strings. It overrides the run() API method of the Runnable where it puts two elements to the BlockingQueue, waiting if necessary for space to become available, with ...

Read More »

Find rhyming words using QuickSort

Bipartite Graph

In this example we shall show you how to find rhyming words using the QuickSort algorithm. We have created two classes, SortThread and ReverseThread that both extend the Thread and override the run() method of Thread. The two threads and the example are described in short: In their run() methods the SortThread calls its private quicksort(String[] str, int low0, int high0) method that ...

Read More »