Java MultiThreading
Java MultiThreading
Q1. Write a java program that will create a thread and set the thread name, display the thread name, get
the thread id, check the thread is currently alive or not.
Q2. Write a java program that will create one child thread. The child thread has to display all even
numbers between m and n, and the main thread will display all odd numbers between m and n.
Q3. Write a java program that will create two threads. Set the priority to each thread and display it.
Q4. Write a java program that will compute dot product of two vector using multithreading.
Assume that the vectors are of size n and p is number of thread used and n is a multiple of p.
Q5. Simple Java thread program to compute the sum of N natural numbers
Objective: Write a Java program to compute the sum of N natural number
Description
This program prints the sum of first N natural numbers. This introduces the concept of a
Synchronized block. Each thread adds its assigned number to a global variable. When all the
threads are done, the global variable will contain the result. It uses a Synchronized block to make
sure that only one thread is updating the variable at any given time
Q6. java thread program to search the minimum number in a given array
Objective : Write a Java thread program to search the Minimum number in a given array.
Description
This program find minimum element in a given set of element. This introduces the concept of a
Synchronized block. Each thread find minimum element in a block of element and compare to
global minimum element. When all the threads are done, the global variable will contain the
minimum element. It uses a Synchronized block to make sure that only one thread is updating the global
minimum variable at any given time
Q8. The producer-consumer problem is one of the most frequently encountered problems when we
attempt multithreaded programming.
The steps to do the consumption of the item produced in independent and not dependent on other items.