NO Guarantee on the order of execution of threads and the join() method

In part-4, we have seen that we can create multiple threads giving the same Runnable. Here we look at the same example and understand the order of their execution.

Three threads t1, t2, and t3 having the same runnable.

Run this…


Multiple Threads and their Stacks

In part-3 we have seen how threads can be created and we also explored the life cycle of a thread to some extent. In this article, we will look at how threads maintain their local variables and call stacks.

Each thread in Java has a private stack associated with it. When a thread is created in Java Virtual Machine, a JVM stack local to that thread is also created.

Below is a simple java application that has one user-defined thread named MyThread along with the main thread.


Life Cycle of a thread with Methods in Thread Class

For managing threads in java, we have many static and instance methods in the Thread class. We can use these methods for creating, starting, pausing, and stopping threads.

Static Methods

  1. static int activeCount()
  2. static Thread currentThread()
  3. static void dumpStack()
  4. static boolean interrupted()
  5. static void sleep()
  6. static void yield()

Instance Methods

  1. void start()
  2. long getId()
  3. String getName()
  4. int getPriority()
  5. void interrupt()
  6. boolean isInterrupted()
  7. boolean isAlive()
  8. void join()
  9. String toString()


Creation and Running a Thread

We have already mentioned in part-1 that a thread is an independent set of instructions that has its own private state. Every Java application has at least one thread named “main” without ourselves creating it. But what does it exactly mean when we say a Java Thread.

Well, a Java Thread is just an instance of a Java Class named Thread.

A thread in Java is just another object of class Thread. This class offers methods to configure and operate on it. …


Program, Process, and a Thread

Multithreading is all about executing the small tasks independently inside a process. Well, there are many articles that explain what a process, thread and concurrency mean. Let me also specify the same in simple words here.

How a process is born ?

A process takes its birth from a static file called a program that contains a specific set of instructions with its associated data. A program, being a static file residing in an auxiliary memory like hard disk, has many extensions depending the programming language. For example, in Java it is .class file or an executable .jar


The perks of merge and rebase

git merge and git rebase are excellent tools for integrating changes from one branch into another. But there is often a confusion about which one to use when.

NOTE: This can be understood better if all the commit histories in the diagrams are thoroughly followed. It will take a little more time but I am sure this will clear out all the confusions that we have about rebase and merge.

For this, we will follow an integrated approach. This post is a little comprehensive and along with git rebase and git merge, we also…


Relational Databases are dominated by NoSQL data stores and here is why.

RDBMS is the wonderful technology serving remarkably well and is still a great choice for many applications. Most of us are well aware of how data are organized in relational databases (as tables and columns) and that they overcome data anomalies and avoid data redundancies. But RDBMS worked well for mid range applications and failed to meet the needs of increasing data, faster querying capabilities and flexibility in data modelling. Here are the 5 reasons why it is tough for RDBMS to handle high work loads and why organizations are moving from RDBMS to NoSQL.

Poor Performance of Join Queries…

KRISHNA KISHORE V

Software Architect, Full Stack Developer, Free Lancer, Technical Content Writer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store