
Concurrency

Quiz
•
Computers
•
1st Grade
•
Hard
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
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);
Similar Resources on Wayground
6 questions
String

Quiz
•
1st - 3rd Grade
10 questions
Mengetik 10 Jari

Quiz
•
1st - 5th Grade
10 questions
Computers

Quiz
•
1st Grade
7 questions
Google Docs

Quiz
•
1st - 5th Grade
7 questions
ICT KEYBOARD

Quiz
•
1st - 3rd Grade
10 questions
G1-W14 - Pre-Keyboarding (Cont.)

Quiz
•
1st Grade
10 questions
Computer Quiz_Ayanta

Quiz
•
1st Grade
14 questions
Review Computer parts and Function keys

Quiz
•
1st Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
20 questions
addition

Quiz
•
1st - 3rd Grade
20 questions
Subject and predicate in sentences

Quiz
•
1st - 3rd Grade
20 questions
Addition and Subtraction facts

Quiz
•
1st - 3rd Grade
20 questions
Place Value

Quiz
•
KG - 3rd Grade
10 questions
Exploring Properties of Matter

Interactive video
•
1st - 5th Grade
10 questions
Odd and even numbers

Quiz
•
1st - 2nd Grade
10 questions
Exploring the 5 Regions of the United States

Interactive video
•
1st - 5th Grade
7 questions
Parts of Speech

Lesson
•
1st - 12th Grade