What happens when you call thread.run() instead of thread.start()?
Only start() creates a new thread of execution; run() is an ordinary method call.
Threads, executors, the memory model, locks, atomics, CompletableFuture, GC and class loading.
Pick an answer to see instantly whether you're right, with an explanation. Questions are shuffled every attempt.
thread.run() instead of thread.start()?Only start() creates a new thread of execution; run() is an ordinary method call.
counter++ 100,000 times on a shared volatile int. The final value is…volatile gives visibility, not atomicity. ++ is read-modify-write, so updates are lost. Use AtomicInteger or a lock.
volatile guarantee?A volatile write happens-before every later read of that variable. It does not make x++ or check-then-act atomic.
volatile?Without volatile, the reference write can be reordered before the constructor writes complete.
ThreadPoolExecutor has core 4, max 16 and an unbounded LinkedBlockingQueue. How many threads will it ever run?Extra threads beyond the core size are only created when the queue is full — an unbounded queue is never full.
ReentrantLock feature does synchronized lack?ReentrantLock adds tryLock, interruptible locking, fairness and multiple conditions; both are reentrant and give visibility.
Consistent lock ordering breaks the circular-wait condition. tryLock with timeouts is another option.
CyclicBarrier is a reusable rendezvous. CountDownLatch is one-shot.
CompletableFuture<User>. Which method chains it without nesting futures?thenCompose is flatMap; thenApply would produce CompletableFuture<CompletableFuture<User>>.
supplyAsync(supplier) tasks run if you pass no executor?The common pool is shared JVM-wide and sized for CPU work — pass a dedicated executor for blocking I/O.
That unmounting is what makes millions of blocking virtual threads cheap. They improve I/O throughput, not CPU speed, and should not be pooled.
new allocated?Objects live on the heap; the stack holds local primitives and references (escape analysis may optimise some allocations away).
Java GCs trace reachability from roots (stacks, statics, JNI), so unreachable cycles are collected too.
ZGC (generational since Java 21) relocates objects concurrently with the application.
Class metadata moved to Metaspace, which grows dynamically (cap it with -XX:MaxMetaspaceSize).
String.class.getClassLoader() return?Core classes are loaded by the bootstrap loader, which is represented as null in Java.
You scored 0 out of 16.