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”

--

--

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