Week 7 Practice Questions
Week 7 Practice Questions
1. Write a java program that implements a multi-thread application that has three threads. First thread
generates random integer every 1 second and if the value is even, second thread computes the square of
the number and prints. If the value is odd, the third thread will print the value of cube of the number.
2. Write a java program for to solve producer consumer problem in which a producer produce a value and
consumer consume the value before producer generate the next value.
3. Write a java program in which thread sleep for 5 sec and change the name of thread.
4. Write a java program in which thread sleep for 6 sec in the loop in reverse order from 5 to 1 and change
the name of thread.
5. Write a java program for multithread in which user thread and thread started from main method
invoked at a time each thread sleep for 1 sec.
6. Write a java program to solve printer synchronization problem in which all the jobs must be completed
in order.
Use ThreadA to find number of digits present in the string k and store into variable dc, finally
print the value of dc(output format: ThreadA:digitscount).
Use ThreadB to find number of alphabetic present in the string k and store into variable cc, finally
print the value of cc(output format:ThreadB:digitscount).
8. Create two objects threadobj1 and threadobj2 for the class UserThreadPriority. Set the name of
threadobj1 as “ThreadA” and threadobj2 as “ThreadB”. Get a String and a Character from the user and
assign into UserThreadPriority class variable k and c respectively. Call the start() method for the thread
objects threadobj1 and threadobj2.
9. Write java program using sleep() method of Thread class where the new class thread created from the
previous class is implemented by using sleep method for 10,20,50,70,100 ns
10. Write a java Thread program using Thread Priority for 5 processes and execute the priority order
among the process.