Examlex

Solved

Consider the AddFirst Method of the LinkedList Class in Chapter

question 41

Multiple Choice

Consider the addFirst method of the LinkedList class in Chapter 16: /**
Adds an element to the front of the linked list.
@param element the element to add
*/
Public void addFirst(Object element)
{
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
First = newNode;
}
Three implementations have been proposed to make the addFirst method thread safe where listLock is a variable of type ReentrantLock. Which of them will work?
I.
ListLock.lock() ;
Try
{
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
}
Finally
{
ListLock.unlock() ;
}
First = newNode;
II.
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
ListLock.lock() ;
Try
{
First = newNode;
}
Finally
{
ListLock.unlock() ;
}
III.
ListLock.lock() ;
Try
{
Node newNode = new Node() ;
NewNode.data = element;
NewNode.next = first;
First = newNode;
}
Finally
{
ListLock.unlock() ;
}


Definitions:

Rubeola

Also known as measles, a highly contagious viral infection characterized by fever, cough, and a distinctive rash.

Rubella

A contagious viral infection best known by its distinctive red rash, also known as German measles, and is of particular concern during pregnancy due to the risk of congenital rubella syndrome.

Sluggish Creatures

Organisms that exhibit slow movement or low activity levels, often as a result of their metabolic rates or environmental conditions.

Sea Bottom

Refers to the lowest part of a sea or ocean, also known as the seabed, where sediments settle and various benthic organisms can be found.

Related Questions