Accessing object using multiple threads


Question 1: Create three classes: storage, printer and counter. The storage class must store an integer. The counter class must make a thread which begins counting from zero and stores each value in the storage class. The printer class must create a thread which keeps reading the value in the storage class and printing it.

Question 2: Create a program which makes an instance of the storage class and sets up a counter and a printer object to operate on it. The program is needed to print only 10 values.

Question 3: Fill up the blanks:

a)  ......... permits a running program to perform some tasks, apparently, at similar time.

b) .................. between threads is taken out automatically by JVM.

c) When we make a thread object, it is stated to be in the .................. state.

d) A thread is stated to be in .................. state when it is suspended, sleeping or waiting in order to satisfy certain condition.

e) .................. is the manner to avoid data corruption caused by simultaneous access to the similar data.

f) The threads communicate through .................. for each other.

g) .................. threads get more CPV time than .................. threads.

h) The .................. technique of the thread class is deprecated in the Java 2.

Question 4: Which of the given statement is correct for the line illustrated below?

Thread myT = new Thread( );

a) The myT is in runnable state.
b) The thread myT has the NORM_PRIORITY.
c) If myT.start( ) is called, the run method in the calling class will be executed.
d) If myT.start( ) is called, the run method in the thread class will be executed.

Question 5: The object class consists of a wait method which is used to coordinate access to an object by multiple threads. Which of the given statements regarding the wait method are true?

a) The wait method is an instance method of object class.
b) The wait( ) method is a static method of object class.
c) To call wait, a thread should have a lock on the object included.
d. An object can have just one thread in the waiting state at a time.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Accessing object using multiple threads
Reference No:- TGS08727

Expected delivery within 24 Hours