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

 

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 »

Thread performance on Atomic type

Bipartite Graph

With this example we are going to demonstrate how to check a thread performance on atomic type. We are testing two runnable objects, one that uses an AtomicInteger and another one that uses a synchronized method. The example is described in short: We have created a class, AtomicRunnable that implements the Runnable, uses an AtomicInteger and in its overriden run() ...

Read More »

Synchronized/Unsynchronized collection performance test

Bipartite Graph

This is an example of how to test the performance of synchronized and unsynchronized Collection. The test is described below: We have a static method, performTest(List l) that adds a new Integer to the specified list for a specified int number of loops. We have also created a class, Timestamp, that in its start() and stop() methods gets the System.nanoTime() ...

Read More »

Safe collection iteration example

Bipartite Graph

In this example we shall show you how to obtain a safe Collection iteration. We are using the List implementation of Collection, but the Collections API provides methods for such operations in other Collection implementations too, such as Map and Set. To obtain a safe Collection iteration one should perform the following steps: Call synchronizedList(List list) API method of Collections ...

Read More »

Vector copy example

Bipartite Graph

With this example we are going to demonstrate how to get a copy of a Vector. We are using the synchronized statement in order to take a safe copy of the Vector’s elements. In short, to get a copy of a Vector you should: Create a new Vector. Populate the vector with elements, using addElement(Object obj) API method of Vector. Set ...

Read More »

List copy example

Bipartite Graph

This is an example of how to make a safe List copy. Making a safe List copy implies that you should: Create a new synchronized ArrayList, using the synchronizedList(List list) API method of Collections. Add elements to the list, using add(Object e) API method of List. Create a new array from the list, using toArray(T[] a) API method of List. ...

Read More »

PriorityQueue example

Bipartite Graph

In this example we shall show you how to use a PriorityQueue. To use a PriorityQueue one should perform the following steps: Create a new Comparator for Integer objects, that is a comparison function, which imposes a total ordering on some collection of objects. Override the compare(Integer i, Integer j) method of Comparator in order to make a specified comparison. Create ...

Read More »

BlockingQueue example

Bipartite Graph

With this example we are going to demonstrate how to use a BlockingQueue. The steps of the example are described in short: We have created two classes that implement the Runnable interface and override its run() API method. The first runnable, FileEnumerationTask has a BlockingQueue of Files, a File that is an empty dump file and another File. It also ...

Read More »

Unbounded work queue example

Bipartite Graph

This is an example of an unbounded work queue. The steps of creating and using an unbounded work queue are described below: We have created a class, WorkQueue that has a LinkedList of Objects and two methods in synchronized statement. The first one is addWork(Object o) and appends an object to the end of the list, using addLast(Object o) API ...

Read More »