Machine-translated by Google. Questions are authored in English.
Top

Threads - General Questions Questions and Answers

Answer: C

newCachedThreadPool takes no size argument, which is the point: the pool grows on demand and retires idle threads. A bounded pool is what newFixedThreadPool provides, and there is no public CachedThreadPool class or newElasticPool method.

Please log in or register to report this question.

Answer: D

Correct answer: private volatile boolean running;

volatile applies only to fields. It cannot qualify a method or a class, and it cannot be combined with final - a final field never changes, so there is nothing for the visibility guarantee to do. A volatile boolean flag is its commonest legitimate use.

Please log in or register to report this question.

Answer: A

The constructor takes the number of parties, with an optional Runnable to run when the barrier trips. There is no no-argument form, no static factory, and a TimeUnit belongs to the await call rather than to construction.

Please log in or register to report this question.

74.

Which of these is NOT a value of the TimeUnit enum?

Answer: B

TimeUnit runs from NANOSECONDS through MICROSECONDS, MILLISECONDS and SECONDS up to DAYS. There is no centisecond constant. Using a constant that does not exist is caught at compile time, which is part of why the enum is preferred to a bare millisecond count.

Please log in or register to report this question.

Answer: C

ConcurrentMap is the interface and ConcurrentHashMap the implementation, so the interface is used as the variable type and the class is constructed. Neither Map nor HashMap offers a method to convert an existing map in place.

Please log in or register to report this question.

76.

A pool needs its worker threads named and marked as daemons. Which method does it call on the ThreadFactory it was given?

Answer: D

A ThreadFactory turns a Runnable into a Thread, so it takes the task and returns the thread, which lets a pool name its threads or mark them as daemons consistently. Returning void would leave the pool with nothing to start.

Please log in or register to report this question.

Answer: A

ExecutorService accepts a Runnable through submit, returning a Future of Object that completes with null, and through execute, which returns nothing. There is no run or start method on the interface; those belong to Runnable and Thread.

Please log in or register to report this question.

Answer: B

ReadWriteLock is the interface and ReentrantReadWriteLock the only implementation in the API. It is not a ReentrantLock, so the two are not assignable to each other, and its read and write locks are obtained afterwards with readLock and writeLock.

Please log in or register to report this question.

Answer: C

Only Callable's method is declared to throw Exception, so a lambda body that calls something with a checked exception fits it and nothing else here. A Runnable returns void, a raw Callable loses the type, and Supplier declares no exception.

Please log in or register to report this question.

80.

Which of these is the correct package declaration for importing every concurrency utility including the locks?

Answer: D

Correct answer: import java.util.concurrent.*; import java.util.concurrent.locks.*;

A wildcard import covers one package and not its subpackages, so java.util.concurrent.* does not bring in the locks. Two imports are needed, and there is no double-asterisk form in Java for reaching a package tree.

Please log in or register to report this question.

Loading…
Tags: Threads - General Questions Questions and Answers || Threads - General Questions MCQ Questions and Answers || Threads - General Questions GK Questions and Answers || Threads - General Questions GK MCQ Questions || Threads - General Questions Multiple Choice Questions and Answers || Threads - General Questions GK || GK on Threads - General Questions || Java Programming Questions and Answers || Java Programming MCQ Questions and Answers || Java Programming GK Questions and Answers || GK on Java Programming