This site is 100% ad supported. Please add an exception to adblock for this site.

Java Threads and Processes

Terms

undefined, object
copy deck
The illusion that two or more tasks are being performed in parallel. ___________ is created by an operating kernel's support of multiple threads.
Concurrency
A _______ has a self-contained execution environment; a complete, private set of basic run-time resources; in particular, each has its own memory space.
process
These exist within a process — every process has at least one. They share the process's resources, including memory and open files. Both provide an execution environment, but creating a new ______ requires fewer resources than creating a new process.
thread
To abstract thread management from the rest of your application, pass the application's tasks to an _________.
executor
The ________ interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method of no arguments called run.
Runnable
The Runnable interface defines method ____, meant to contain the code executed in the thread.
run
The Thread class implements Runnable, though its run method does nothing. An application can ________ Thread, providing its own implementation of run.
subclass
What code is used to cause the current thread to suspend execution for a specified period?
Thread.sleep();
The join method allows one thread to wait for the completion of another. If 't' is a Thread object whose thread is currently executing, this code:

________;

causes the current thread to pause execution until t's thread terminates.
t.join()
Thread ____________ happens when two operations, running in different threads, but acting on the same data, interleave. This means that the two operations consist of multiple steps, and the sequences of steps overlap.
Interference
True or False: When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object suspend execution until the first thread is done with the object.
True
________ describes a situation where two or more threads are blocked forever, waiting for each other.
Deadlock
__________ describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. This happens when shared resources are made unavailable for long periods by "greedy" threads.
starvation
A thread often acts in response to the action of another thread. If the other thread's action is also a response to the action of another thread, then ________ may result. As with deadlock, these threads are unable to make further progress. However, the
livelock
A _______ _____ invokes Object.wait to suspend the current thread. The invocation of wait does not return until another thread has issued a notification that some special event may have occurred — though not necessarily the event this thread is waiting
guarded block
There are three types of executor interfaces defined in java.util.concurrent, which one is this:

A simple interface that supports launching new tasks.
Executor
The Executor interface provides a single method, execute, designed to be a drop-in replacement for a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace

(new Thread(r)).start();

with
e.execute(r);
The ExecutorService interface supplements execute with a similar, but more versatile ______ method. Like execute, this method accepts Runnable objects, but also accepts Callable objects, which allow the task to return a value. This method returns a Futur
submit
The ScheduledExecutorService interface supplements the methods of its parent ExecutorService with ________, which executes a Runnable or Callable task after a specified delay.
schedule
This type of pool always has a specified number of worker threads running; if a thread is somehow terminated while it is still in use, it is automatically replaced with a new thread. Tasks are submitted to the pool via an internal queue, which holds extr
Fixed Thread Pool
What exactly would this code do?

Executorservice threadExecutor = Executors.newFixedThreadPool(3);
This code would create a new fixed thread pool with a maximum of 3 threads available.
The ___________________ method creates an executor with an expandable thread pool. This executor is suitable for applications that launch many short-lived tasks.
newCachedThreadPool
To directly control thread creation and management, simply instantiate class ______ each time the application needs to initiate an asynchronous task.
Thread
To make a method synchronized, simply add the ____________ _______ to its declaration.
synchronized keyword
There are three types of executor interfaces defined in java.util.concurrent, which one is this:

A subinterface of Executor, which adds features that help manage the lifecycle, both of the individual tasks and of the executor itself.
ExecutorService
There are three types of executor interfaces defined in java.util.concurrent, which one is this:

A subinterface of ExecutorService, supports future and/or periodic execution of tasks.
ScheduledExecutorService
The ScheduledExecutorService interface defines ___________________ and ______________________, which executes specified tasks repeatedly, at defined intervals.
scheduleAtFixedRate and scheduleWithFixedDelay
The _______________________ method creates an executor that executes a single task at a time.
newSingleThreadExecutor

Deck Info

28

permalink