wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Multithreading

Total questions: 10

Worksheet time: 11mins

Name
Class
Date
1.

What will happen if two thread of the same priority are called to be processed simultaneously?

a)

Anyone will be executed first lexographically

b)

Both of them will be executed simultaneously

c)

None of them will be executed

d)

It is dependent on the operating system

2.

What is the priority of the thread in the following Java Program?

class multithreaded_programing

{

public static void main(String args[])

{

Thread t = Thread.currentThread(); System.out.println(t);

} }

a)

4

b)

5

c)

0

d)

1

3.

Deadlock is a situation when thread is waiting for other thread to release acquired object.

a)

True

b)

False

4.

Which of these keywords are used to implement synchronization?

a)

synchronize

b)

syn

c)

synch

d)

synchronized

5.

Which of these method is used to tell the calling thread to give up a monitor and go to sleep until some other thread enters the same monitor?

a)

wait()

b)

notify()

c)

notifyAll()

d)

sleep()

6.

What is synchronization in reference to a thread?

a)

It’s a process of handling situations when two or more threads need access to a shared resource

b)

It’s a process by which many thread are able to access same shared resource simultaneously

c)

It’s a process by which a method is able to access many different threads simultaneously

d)

It’s a method that allow too many threads to access any information the require

7.

synchronized instance methods acquire lock on

a)

object

b)

class

c)

all

d)

none

8.

What will be the output of the program?

class Test implements Runnable {

public

void run()

{

System.out.println("Run");

}

} class Myclass {

public

static void main(String[] args)

{

Thread t1 = new Thread();

t1.start();

System.out.println("Main");

}

}

a)

Run

b)

Main

c)

Compile Time Error

d)

Run Main

9.

What will be the output of the following?

class ThreadTest extends Thread

{

public void run()

{

for(int i = 0; i < 3; i++)

{

System.out.println("A");

System.out.println("B");

}

}

}

class ThreadDemo extends Thread

{

public void run()

{

for(int i = 0; i < 3; i++)

{

System.out.println("C");

System.out.println("D");

}

}

}

public class Simple{


public static void main(String args[])

{

ThreadTest t1 = new ThreadTest();

ThreadDemo t2 = new ThreadDemo();

t1.start();

t2.start();

}

}

a)

Will print in this order ABCD...ABCD...

b)

Compile time Error There is no start() method.

c)

Will print A B C D but we cannot predict the Order in which this will be printed.

d)

Will print in this order AB CD AB...

e)

None of these.

10.

Which method must be defined by a class implementing the java.lang.Runnable interface?

a)

public void start()

b)

public void run()

c)

void run()

d)

None of these