Java Concurrency(pseudo -parallelism): Part II

The application is running on multi-core and multi-threaded environment
EX:
public class HelloThread extends Thread {
public void run() {
System.out.println("Hello from a thread!");
}

public static void main(String args[]) {
(new HelloThread()).start();
}
}
public class SampleClass implements Runnable {@Override
public void run() {
System.out.println("Thread has ended");
}
public static void main(String[] args) {
SampleClass ex = new SampleClass();
Thread t1= new Thread(ex);
t1.start();
System.out.println("Hello");
}
}
O/p :- Hello
Thread has ended
Thread pool
EX:-public class Singleton{
private static volatile Singleton _instance;
public static Singleton getInstance(){
if(_instance == null){
synchronized(Singleton.class){
if(_instance == null)
_instance = new Singleton();
}
}
return _instance;
}
}
//Note:- If object try to lock synchronised block code then synchronized block will throw “NullPointerException”

--

--

--

Technical Consultant | Passionate about exploring new Technology | Cyber Security Enthusiast | Technical Blogger | Problem Solver

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building effective security OKRs

Nudging Novices: Five Persuasive Patterns

Mountebank and Continuous Delivery

From the Students’ Perspective

Sandman: a cloud-based platform for facilitating agile, scalable agent-based modelling

Allow a remote IP to connect to your Amazon RDS MySQL Instance

Fake(r) It ’Til You Make It.

Robotics for Beginners: All you need to know!

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
Kumar Shivam

Kumar Shivam

Technical Consultant | Passionate about exploring new Technology | Cyber Security Enthusiast | Technical Blogger | Problem Solver

More from Medium

Java Microservice Layer Architecture

Guide to AtomicBoolean in Java

Differentiate Integration & Unit tests in Gradle: Spring boot

Introduction to Dynamic Proxies in Java