Multithreading

What Should you know in Multithreading 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
  • Deadlock
  • Java ExecutorService
  • Java Callable
  • Java Future
  • 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