Multithreading

What Should you know in Multithreading in java
  • Volatile Vs Static Vs  Static Volatile : Read in details Volatile Vs Static In Java
  • wait() this is method of object class. 
  • notify() this is method of object class. 
  • nofifyAll() this is method of object class. 
  • sleep() this is method of thread
  • Yield() this is method of thread
  • Join() this is method of thread
  • public void interrupt() 
  • public static boolean interrupted() 
  • public boolean isInterrupted() 
  • Fairness in Multithreading
  • Submit() Vs execute()  Differences Between Submit and Execute methods
  • Difference Between Callable and Runnable Interface in Java
  • java.util.concurrent - Java Concurrency Utilities
  • BlockingQueue
  • ArrayBlockingQueue
  • DelayQueue
  • LinkedBlockingQueue
  • PriorityBlockingQueue
  • SynchronousQueue
  • BlockingDeque
  • LinkedBlockingDeque
  • ConcurrentMap
  • ConcurrentNavigableMap
  • CountDownLatch
  • CyclicBarrier
  • Exchanger
  • Semaphore
  • Binary Semaphore
  • Mutex
  • Starvation : Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. This happens when shared resources are made unavailable for long periods by "greedy" threads. Reference 
  • Deadlock : In Java, a deadlock is a situation when two or more threads are blocked forever, waiting for each other Example : thread1 hold lock on resource R2 and waiting for resource R1 and thread2 hold lock on ressource R1 and waiting for resource R2 So it will create dedlock because both threads are not able to complete their process . Reference
  • Race Condition : In Java, Race condition  is a type of concurrency bug or issue that is introduced in our program due to  parallel execution of our program when more than one thread try to access a shared resource (modify, write) at the same time. This is occure due to without proper synchronization and the operator interleaves on each other. Example : thread1 and thread2 access same resource at same time, thread1 trying to increment count and thread2 trying decrease count.
  • Java ExecutorService
  • Java Callable
  • Java Future
  • CompletableFuture
  • ExecutorCompletionService
  • ThreadPoolExecutor
  • ScheduledExecutorService
  • Java Fork and Join using ForkJoinPool
  • Lock
  • ReadWriteLock
  • AtomicBoolean
  • AtomicInteger
  • AtomicLong
  • AtomicReference
  • AtomicStampedReference
  • AtomicIntegerArray
  • AtomicLongArray
  • AtomicReferenceArray
Q- What is multithreading in java? Or what do you mean by multithreading?
  • Multithreading is one of the most powerful feature of Java.
  • Threads are light-weight processes within a process.
  • Java allows to split a program into more than two parts as threads and that threads can execute concurrent.  
  • Multithreading is similar to multitasking but each thread have its own stack to execute and share the same memory address.
  • The purpose of multithreading is to enable simultaneous execution of two or more parts of a program to utilize maximum CPU usage. Thus enhancing the CPU performance
Q- Do Java threads share same memory?
In Java threads are part of the same process (a program), hence threads share the same memory address. However JVM, doesn't allow the threads to access each other's stacks (i.e. local variables)

Q- Why do we use threads in java?
By using threads in java its make java application faster by doing multiple things at same time. Thread java application to achieve parallelism in Java program.
As threads works independently and provides the maximum utilization of the CPU, so enhance the performance of CPU.

Q- Which memory area is used to execute a thread in java?
Answer : Stack Memory.

Q- How many types of thread pool are there in Java? Or How many ways to create thread pool in java?
There are total 5 ways to create/use thread pool in java.its depends on requirements which one you want to use. click here to read more on Executor Framework in Java.
  • Single Thread Executor: Executors.newSingleThreadExecutor()
  • Cached Thread Pool: Executors.newCachedThreadPool()
  • Fixed Thread Pool: Executors.newFixedThreadPool()
  • Scheduled Thread Pool: Executors.newScheduledThreadPool()
  • Single Thread Scheduled Pool: Executors.newSingleThreadScheduledExecutor()
Q- Does multithreading improve performance?
Q- How do you stop a thread in Java?
Q- How do you kill a thread in Java?
Q- How do you stop a running thread in Java?
Q- How do I stop a method in Java?
Q- Does System Exit kill all threads?
Q- How do you start a thread in Java?
Q- What happens when a thread is interrupted Java?
Q- Why is multithreading needed?
Q- What happens if we start a thread twice?
Q- How to Run Threads in Sequence? Or How to Run Threads in Sequence without join? Or How to make sure sequence of threads in java?



Related Tutorial

No comments:

Post a Comment