Multithreading

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What are the two ways to create a thread within a process?

1) Create a new class extends type Thread 2) Create a new class to implement the Runnable interface

A blocked thread can OR cannot use a processor, even if one is available.

A blocked thread cannot use a processor, even if one is available.

thread 1 waiting for thread 2, but t2 waiting for t1 .. known as

Deadlock

An ExecutorService object is created by calling a static method of which class?

Executors

Name the Thread Life Cycle and States

New Runnable Blocked Waiting Timed Waiting Terminated

What are two fundamental problems with multithreading

No knowledge of when a thread will run and multiple threads may try to access the same resource

Do thread priorities guarantee order of thread execute? y / n

No. even with thread priorities, the operating system (not priorities) determines the order in which threads execute.

With timeslicing, each thread is given a limited amount of time, called a __________, to execute on a processor.

Quantum

The Worker class has observable states defining the lifecycle of an object:Name the observable states.

Ready - initial state Scheduled - scheduled for work Succeeded - completed successfully Failed - exceptions occurred Cancelled - interrupted

A thread can be put in waiting state for various reasons e.g. calling it's wait() method. Usually program puts a thread in WAIT state because something else needs to be done prior to what current thread is doing Once the thread wait state is over, its state is changed to ________ and it's moved back to thread pool.

Runnable

True or False: the OS hides the Runnable and Running states from the JVM which sees only the Runnable state?

True

True or False:There is not a reliable means of cancelling tasks in Java, therefore best practive of JavaFX tasks is to periodically check if they have been cancelled - using isCancelled()

True

Tasks are responsible for the implementation of the work done in the _________

background

A Runnable thread transitions to the _______ state when it attempts to perform a task that cannot be completed immediately and it must temporarily wait until that task completes

blocked

What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY? a) 0 & 256 b) 0 & 1 c) 1 & 10 d) 1 & 256

c

Which of these method is used to explicitly set the priority of a thread? a) set() b) make() c) setPriority() d) makePriority()

c

Which of these method is used to find out that a thread is still running or not? a) run() b) Alive() c) isAlive() d) checkRun()

c

Which of these method waits for the thread to treminate? A. sleep() B. isAlive() C. join() D. stop()

c

Which of these method waits for the thread to treminate? a) sleep() b) isAlive() c) join() d) stop()

c

producer/consumer relationship, the ________ portion of an application generates data and stores it in a shared object, and the ________ portion of an application reads data from the shared object

producer, consumer

Give an example of a class that multithreaded for reading lines

public class ReaderTask extends Task<String> { protected String call() { String result = null;// read in data from a file result = in.readLine();return result; } }

The BlockingQueue interface declares which two methods for blocked adding and blocked removing of elements from a circular buffer?

put and take.

A waiting thread transitions back to the ________ state only when another thread notifies it to continue executing.

runnable

Calling start() method on a thread puts it in a ______ state. At this point, execution control is passed to the OS thread scheduler to finish its execution.

runnable

A task utilizing its cpu time is said to be in a _________ state. When this time expires it returns to the runnable state and the OS assigns another thread to the processor.

running

The ArrayBlockingQueue method ________ returns the number of elements currently in the ArrayBlockingQueue?

size

What two methods can place a thread into a Timed Waiting state

sleep(long millis) wait(long millis)

postpone—possibly indefinitely—the execution of lower-priority threads. such indefinite postponement is sometimes referred to more colorfully as________.

starvation

Sharing resources between threads is done with __________

synchronization

In order to prevent threads collision over resources, methods can be declared as _____, only allowing one thread to call the method of a particular object.

synchronized

When a __________ method or block is running on an object, the object is locked so no other such method can run on that object at the same time.

synchronized

when I/O request completesthe blocked thread transitions to

the runnable state, so it can resume execution.

A ______ is a path of execution through a program

thread

Once a Task has been created it can be started via a ________

thread

Inside processes we utilize _____ to execute code concurrently

threads

timed waiting threads and waiting threads can OR cannot use a processor if available?

timed waiting threads and waiting threads CANNOT use a processor, even if one is available.

When a thread obtains the monitor lock on an object, then determines that it cannot continue with its task on that object until some condition is satisfied, the thread can call Object method _____

wait

How do you create a concurrent thread by extending the Thread class?

create a class that extends Thread. override the run() method. To run the class, instantiate the class (creating a new thread) then call start().

How do you create a concurrent thread by using the Runnable interface?

create a class that implements Runnable. Implement the run() method. to run the class, instantiate the class (creating a new thread) then call start().

How do you create a condition on a lock? A. Condition condition = Lock.getCondition(); B. Condition condition = Lock.newCondition(); C. Condition condition = lock.getCondition(); D. Condition condition = lock.newCondition();

d

Which of the following expressions must be true if you create a thread using Thread = new Thread(object)? A. object instanceof Applet B. object instanceof Thread C. object instanceof Frame D. object instanceof Runnable

d

Which of these statement is incorrect? a) A thread can be formed by implementing Runnable interface only. b) A thread can be formed by a class that extends Thread class. c) start() method is used to begin execution of the thread. d) run() method is used to begin execution of a thread before start() method in special

d

Which one of the following statements is true with regard to a producer/consumer relationship with one producer and one consumer?

A producer can produce more items than a consumer consumes.

Which of these method is used to implement Runnable interface? a) stop() b) run() c) runThread() d) stopThread()

b

Multithreading can increase performance only on multi-core systems or single processor too?

BOTH. . Actually, multithreading can also increase performance on single-processor systems

t/f Thread scheduling is platform independent.

FALSE. platform dependent—the behavior of a multithreaded program could vary across different Java implementations.

True or False: When a thread issues an input/output request the operating system keeps the thread in the running state until the I/O request completes.

False

What are some specific uses for threads?

Long initiations (read long file) Repetitive or timed tasks (animations) Asynchronous events (event handling such as a mouse click) Multiple Tasks (To do more than one thing at once)

A runnable thread enters the ________ state (sometimes called the dead state) when it successfully completes its task or otherwise terminates (perhaps due to an error)

Terminated

A thread enters the _________ state (sometimes called the dead state) when it successfully completes its task or otherwise terminated due to any error or even it was forcefully killed.

Terminated

Which of the following is true for a correct producer/consumer relationship with one producer, one consumer, and a 5-cell buffer?

The consumer can consume when all cells are full.

In a producer/consumer relationship with a single cell of shared memory, which of the following is true?

The producer must run first or the consumer will have to wait.

The javafx.concurrent package facilitates thread interaction for JavaFX applications.Name the 3 important aspects of this package and what their role is

Worker - interface Task - abstract subclass of Worker Service - executes tasks, subclass of Worker

The Runnable interface is more general than the Thread class. You can convert any class that extends Thread to a class that implements Runnable. A. true B. false

a

To run an object on a separate thread, the object must be a subclass of Thread. A. true B. false

a

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) Its a process by which many thread are able to access same shared resource simultaneously. c) Its a process by which a method is able to access many different threads simultaneously. d) Its a method that allow to many threads to access any information require.

a

Which of these interface is implemented by Thread class? a) Runnable b) Connections c) Set d) MapConnections

a

Operating systems employ a technique called ________ to prevent indefinite postponement

aging

Which of these method can be used to make the main thread to be executed last among all the threads? A. stop() B. sleep() C. join()

b

Which of these method can be used to make the main thread to be executed last among all the threads? a) stop() b) sleep() c) join() d) call()

b

Two tasks that are operating ________ are executing simultaneously.

in parallel

In order to prevent two, or more threads, attempting to access the same resource, a _____ is put on the resource

lock

Processes are instances of programs which typically run independent to each other.______ allocated by OS

memory

As soon as you create a new thread, its in a ____ state and remains in the state until the program starts the thread using its start() method. Note: At this point, the thread is not alive and its a state internal to java programming.

new

A new thread begins its life cycle by transitioning to the __________ state.

new (new state)

is ExecutorService object in separate thread?

no, it is not an object that can be run in separate thread. false.

When a thread executing a synchronized statement (or method) completes or satisfies the condition on which another thread may be waiting, it can call Object method ________ or ________

notify, notifyAll

Java has 3 levels of synchronization, what are they

object level method level block level

Concurrency is a subset of parallelism OR parallelism is a subset of concurrency?

parallelism is a subset of concurrency.

A runnable thread transitions to the blocked state when it attempts to

perform a task that cannot be completed immediately and it must temporarily wait until that task completes.


संबंधित स्टडी सेट्स

Font: Basic Editing Features Office Applications I: Tutorials for Microsoft® Word®, PowerPoint®, and Publisher®

View Set

Medieval Europe lesson 3 Kingdoms & Crusades

View Set

Carbon, Nitrogen, and Water Cycles

View Set

Fundamentals of Strategic Decision Making - Exam 1

View Set

Lesson 13 Late 20th Century True False Quiz

View Set