Question: Please answer all questions. Beginning Java with NetBeans: Chapter 18 How to work with threads MULTIPLE CHOICE [Answers are in tables delete all but the

Please answer all questions.

Beginning Java with NetBeans: Chapter 18

How to work with threads

MULTIPLE CHOICE [Answers are in tables delete all but the correct answers cell]

What part of the operating system controls the execution of threads?

a.

thread scheduler

c.

task controller

b.

execution scheduler

d.

run scheduler

Which of the following is not one of the typical uses for threads?

a.

To improve the speed of numeric computations

b.

To improve the performance of applications with extensive I/O operations

c.

To allow two or more users to run server-based applications simultaneously

d.

To improve the responsiveness of GUI applications

Which of the following interfaces can be used to create a thread?

a.

Thread

c.

Scheduler

b.

Runnable

d.

Task

Which of the following is not one of the valid states of a thread?

a.

New

d.

Blocked

b.

Runnable

e.

Waiting

c.

Running

Which statement most accurately describes a thread in the Runnable state?

a.

The thread is available for execution, but is not yet executing.

b.

The thread is either available for execution or is currently executing.

c.

The thread has been created but its start method has not yet been called.

d.

The threads sleep method has been called.

Which package is the Thread class stored in?

a.

java.threading

c.

java.system

b.

java.lang

d.

java.task

What method do you override to provide the code thats executed by a thread?

a.

exec

c.

run

b.

start

d.

task

Consider the following program:

public class CountDownApp { public static void main(String[] args) { Thread t1 = new CountDown(); Thread t2 = new CountDown(); t1.start(); t2.start(); } }

Assuming that the CountDown class extends the Thread class, how many threads are used to run this program?

a.

1

c.

3

b.

2

d.

4

How long will a thread that executes the following statement sleep?

Thread.sleep(50);

a.

exactly 50 milliseconds

c.

at least 50 milliseconds

b.

at most 50 milliseconds

d.

none of the above

What exception is thrown by the sleep method?

a.

InterruptedException

c.

ThreadPausedException

b.

NoSuchThreadException

d.

ThreadException

Which of the following shows the proper position of the synchronized keyword in a class declaration?

a.

public int synchronized calculate(int x)

b.

public synchronized int calculate(int x)

c.

public int calculate(synchronized int x)

d.

public int calculate(int x) synchronized

Which of the following situations would indicate that a method does not need to be synchronized?

a.

The method doesnt accept parameters.

b.

The method doesnt have a return value.

c.

The method contains only a single Java statement.

d.

The method will never be called by more than one thread.

Which of the following statements is true when a method specifies the synchronized keyword?

a.

The entire object will be locked whenever any thread executes the method, so even unsynchronized methods are unavailable until the synchronized method finishes.

b.

All other threads in the application will be suspended until the synchronized method completes.

c.

Only one thread at a time will be allowed to execute the method. Any other threads that attempt to execute the method will be forced to wait until the method finishes for the current thread.

d.

Multiple threads can execute the method simultaneously. The task scheduler will automatically switch the execution among the various threads.

COMPLETION

A/an ________________ is a single sequential flow of control within an application that often completes a specific task.

________________ threads execute independently of each other.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!