Java.Multithreading

Explain the Java memory model?

What is main main memory, is it heap ?

HappensBeforeExample

What is “thread safety”?

What is the difference between “concurrency” and “parallelism”?

If i use ThreadPoolExecutor, may it be possible that tasks will be executed on different cores ?

if i use ForkJoin is it guaranteed to solve each task on different core ?

Is ForkJoin more effective than threadExecutor ?

Can i adjust ThreadPoolExeccutor to work on different cores ?

What is “cooperative multitasking”? What type of multitasking does Java use? What is the reason for this choice?

What is ordering, as-if-serial semantics, sequential consistency, visibility, atomicity, happens-before, mutual exclusion, safe publication?

What is the difference between a process and a thread?

What are “green threads” and do they exist in Java?

How can a thread be created?

What is the difference between Thread and Runnable?

What is the difference between start() and run() methods in Thread?

How can a thread be started forcibly?

What is a “monitor” in Java?

Why do we need Synchronized (this) and Synchronized method if they give us the same result ?

Give me details about monitor, i cannot understand how it can synchronize only part of the method if we locking whole the object ?

if you say monitor is the mutex, tell me in terms of mutex how sync happens ?

Define the concept of “synchronization”.

What are the different types of synchronization in Java?

When to use what ?

Example with consumer and producer

What states can a thread be in?

Can new instances of a class be created while a static synchronized method is executing?

Why might a private mutex be needed?

How do wait() and notify()/notifyAll() methods work?

What is the difference between notify() and notifyAll()?

Why are wait() and notify() methods called only in a synchronized block?

How does Thread.join() work?

What is a livelock?

Deadlock

What is a livelock?

How can I check if a thread holds the monitor of a specific resource?

On which object does synchronization occur when calling a static synchronized method?

What is the use of the volatile, synchronized, transient, native keyword?

What is the difference between volatile and Atomic variables?

What is the difference between java.util.concurrent.Atomic*.compareAndSwap() and java.util.concurrent.Atomic*.weakCompareAndSwap().

What does “thread priority” mean?

What are “daemon threads”?

Can the main thread of a program be made a daemon?

What does it mean to put a thread to sleep?

What is the difference between the two interfaces Runnable and Callable?

What is FutureTask?

What is the difference between CyclicBarrier and CountDownLatch?

What is a race condition?

Is there a way to solve a race condition?

How CAS works under the hood and how it helps in sychronization ?

In Counter class we dont use compareAndSet method, so how it works ?

How to stop a thread?

Why is it not recommended to use Thread.stop()?

What happens when an exception is thrown in a thread?

What is the difference between interrupted() and isInterrupted()?

What is a thread pool?

How big should a thread pool be?

What happens if the thread pool queue is already full but a new task is submitted?

What is the difference between submit() and execute() methods in a thread pool?

What is callable and future ? how are they connected ?

Future and CompletableFuture.

What is the difference between stack and heap in terms of multithreading?

How to share data between two threads?

What is the JVM startup parameter used to control the size of a thread stack?

How to dump a thread?

What is a ThreadLocal variable?

When should i call threadLocal.remove()

What is the difference between synchronized and ReentrantLock?

What is ReadWriteLock?

What is starvation f threads in ReadWriteLock ?

What is a “Fork/Join framework”?

What is Semaphore?

What is double checked locking Singleton?

How to create a thread-safe Singleton?

Explain Enum Singleton, why does it Protects against reflection & serialization attacks ?

Why enum singletone is it thread safe ?

Why are immutable objects useful?

What is busy spin?

List the principles you follow in multithreaded programming?

Given 3 threads T1, T2 and T3? How to implement execution in sequence T1, T2, T3?

Write a minimal non-blocking stack (only two methods – push() and pop()).

Write a minimal non-blocking stack (only two methods – push() and pop()) using Semaphore.

Write a minimal non-blocking ArrayList (only four methods – add(), get(), remove(), size()).

Write a thread-safe implementation of a class with a non-blocking BigInteger next() method that returns the elements of the sequence: [1, 2, 4, 8, 16, …].

Write a simple multi-threaded bounded buffer using synchronized.

Write a simple multi-threaded bounded buffer using ReentrantLock.