Suresh and Ramesh started creating an application where it requires to do some mathematical operations. They are going to deploy it in a server. They wanted to do simultaneous execution of multiple parts of programs to utilize CPU time. They decided to create 2 separate threads for operations: num**2 and sqrt(num) with sleep of 100ms each. Write a program containing two threads and each thread should have a sleep of 100 ms. One thread is for calculating the square of the elements in the array and other is for square roots. Trace the output in the threads only. Use
Suresh and Ramesh started creating an application where it requires to do some mathematical operations.
They are going to deploy it in a server. They wanted to do simultaneous execution of multiple parts of
programs to utilize CPU time. They decided to create 2 separate threads for operations: num**2 and
sqrt(num) with sleep of 100ms each.
Write a program containing two threads and each thread should have a sleep of 100 ms. One thread is for
calculating the square of the elements in the array and other is for square roots.
Trace the output in the threads only. Use Exception handling to handle and trace the interruptions if they occur.
Input: An array. Can use static data. Preferably try to use run() and start().
Output:
"Thread 1"+ square(num)
"Thread 2"+ square root(num)
likewise to distinguish the thread status
Step by step
Solved in 2 steps