Java Synchronization Basics

Last Updated :
Discuss
Comments

Question 1

Why is synchronization used in Java multithreading?

  • To improve CPU performance

  • To allow multiple threads to execute at once

  • To prevent data inconsistency and race conditions

  • To increase thread priority

Question 2

Which keyword is used to synchronize a method in Java?

  • lock

  • sync

  • synchronized

  • atomic

Question 3

Which of the following can be synchronized in Java?

  • Methods only

  • Constructors

  • Blocks and Methods

  • Interfaces

Question 4

Which object does a synchronized instance method lock on?

  • Class object

  • The method itself

  • The this object

  • The parent class

Question 5

How do you synchronize a block of code inside a method?

  • lock(this)

  • synchronize(this)

  • synchronized(this) { /* code */ }

  • Thread.lock(this) {}

Question 6

Which type of lock is acquired when using a static synchronized method?

  • Instance lock

  • Local lock

  • Class-level lock

  • Method-level lock

Question 7

What happens if two threads access a non-synchronized method of the same object?

  • One thread waits

  • Both can execute concurrently

  • Compilation error

  • JVM throws exception

There are 7 questions to complete.

Take a part in the ongoing discussion