Concurrency

Concurrency

1st Grade

9 Qs

quiz-placeholder

Similar activities

Test de Programación Java

Test de Programación Java

1st Grade

6 Qs

認識鍵盤

認識鍵盤

1st - 5th Grade

8 Qs

Jr 1 - Unit 3 : Working with Text

Jr 1 - Unit 3 : Working with Text

1st Grade

10 Qs

Close Reading the Interent

Close Reading the Interent

KG - University

10 Qs

Word, uređivanje teksta, 1. razred

Word, uređivanje teksta, 1. razred

1st - 5th Grade

13 Qs

Programación Java

Programación Java

1st Grade

10 Qs

Назначение клавиш клавиатуры

Назначение клавиш клавиатуры

1st - 5th Grade

10 Qs

MS Access Database

MS Access Database

KG - University

10 Qs

Concurrency

Concurrency

Assessment

Quiz

Computers

1st Grade

Hard

Created by

Jose Diaz

Used 1+ times

FREE Resource

9 questions

Show all answers

1.

MULTIPLE SELECT QUESTION

3 mins • 1 pt

Which of the following options correctly create an ExecutorService instance?. Please select 2 options.

var es = ExecutorService.getInstance();

var es = new ExecutorService();

var es = Executors.newFixedThreadPool(2);

var es = Executor.getSingleThreadExecutor();

var es = Executors.newVirtualThreadPerTaskExecutor();

2.

MULTIPLE SELECT QUESTION

3 mins • 1 pt

Which of the following code fragments will you use to create an ExecutorService?. Please select 3 options.

ExecutorService

Executor

Executors

.newSingleThreadExecutor();

.newVirtualThreadPerTaskExecutor();

3.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Which of the following statements correctly create a virtual thread? (Assume that r refers to a Runnable instance.). Please select 1 option.

Thread t = new VirtualThread(r);

Thread t = new VirtualThread(r);

VirtualThread t = Thread.ofVirtual();

Thread t = Thread.ofVirtual();

Thread t = Thread.ofVirtual().unstarted(r);

4.

MULTIPLE SELECT QUESTION

3 mins • 1 pt

Given:

ReadWriteLock rl = new ReentrantReadWriteLock();

Lock rlock = rl.readLock();

Lock wlock = rl.writeLock();

Identify correct statements regarding code that appears after the above code. (Consider each option individually.). Please select 3 options.

rlock.lock();
System.out.println("read lock acquired");
wlock.lock();
System.out.println("write lock acquired");

This code will print both the statements.

wlock.lock();
System.out.println("write lock acquired");
rlock.lock();
System.out.println("read lock acquired");

This code will print both the statements.

rlock.lock();
System.out.println("read lock acquired");
rlock.lock();
System.out.println("read lock acquired again");

This code will print both the statements.

rlock.lock();
rlock.lock();
rlock.unlock();
wlock.lock();
System.out.println("write lock acquired");

This code will print the statement.

rlock.lock();
try{
    wlock.tryLock();
    wlock.unlock();
    System.out.println("write lock acquired ");
}catch(Exception e) {
    e.printStackTrace();
}

This code will print an exception stack trace.

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

You have a collection (say, an ArrayList) which is read by multiple reader threads and which is modified by a single writer thread. The collection allows multiple concurrent reads but does not tolerate concurrent read and write. Which of the following strategies will you use to obtain best performance?. Please select 1 option.

synchronize all access to the collection.

make the collection variable final.

make the collection variable final and volatile.

Wrap the collection into its synchronized version using Collections.synchronizedCollection().

Encapsulate the collection into another class and use ReadWriteLock to manage read and write access

6.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

What will the following code print?

AtomicInteger ai = new AtomicInteger();

Stream<Integer> stream = Stream.of(11, 11, 22, 33).parallel();

stream.filter(

e->{ ai.incrementAndGet();

return e%2==0;

});

System.out.println(ai); Please select 1 option.

0

Any number between 1 to 4.

4

Any number between 0 to 3

7.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

If a synchronized method ends up throwing an exception to the caller, the lock acquired by the thread associated with this method due to the usage of the synchronized keyword is released automatically. Please select 1 option.

true

false

8.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

Please select 1 option.

It may print any combination of the keys except an empty list.

It may print any combination except: c,

It may print any combination except: a, or b, or a, b, or b, a or an empty list.

It may print any combination except: b, c,

It may print any combination except: a, b,

9.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

What can be inserted at //2 so that 6 will be printed by the following code?

AtomicInteger ai = new AtomicInteger(5);

//2 INSERT CODE HERE

System.out.println(x);

Please select 2 options.

int x = ai.increment();

int x = ai.getAndIncrement();

int x = ai + 1;

int x = ai.incrementAndGet();

int x = ai.addAndGet(1);