Archive for category Core Java

Exchanger

Java concurrency API provides a synchronization utility java.util.concurrent.Exchanger that allows two threads to exchange data. Exchanger provides a common point where two threads arrive and exchange data between them such that data of first thread goes to the second thread and data of second thread goes to first. Exchanger basically creates a barrier at which […]

, , ,

Leave a comment

Batch Processing using JDBC

,

Leave a comment

Using local thread variables

Shared data is one of the most critical aspect of concurrent programming. When you create an instance of a class that implements Runnable interface or extends Thread class and use same object to create multiple Threads then all the threads share same attributes. This means if you change any attribute in one thread, all threads […]

, , ,

Leave a comment

Difference between Wait and Sleep in Java

I am listing here differences between wait() and sleep() methods in java. Please feel free to suggest if you can think of anything apart from those listed below. Wait Sleep Wait method release the acquired monitor while the thread waits Sleep method holds the monitor while the thread goes to sleep Wait method should be […]

, ,

Leave a comment

Returning Data from Java Threads

There are a couple of ways in which threads can be created. i.e. Implementing Runnable Interface and extending Thread Class (Example here). Further we need to implement run method and do our processing inside the run method. This would look like below. One thing to note about above snippet is the return type of run() […]

, , ,

6 Comments

Creating and Running thread in Java

Like any other Object in java, Threads are Objects. There are a couple of ways threads can be created in Java. Extending the Thread class and overriding it’s Run() method Building a class that implements Runnable Interface and implementing it’s run() method. Then create an Object of the Thread class and pass an instance of […]

, , ,

1 Comment

Bubble Sort in Java

Bubble Sort is a generic algorithm to sort the elements and can be implemented in any programming language. The algorithm gets its name from the way smaller elements “bubble” to the top of the list. it is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair […]

, , ,

Leave a comment