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
Which keyword is used to synchronize a method in Java?
What is the output of the following code?
Java
public synchronized void print() {
System.out.println("Start");
try { Thread.sleep(100); } catch (Exception e) {}
System.out.println("End");
}
Will always print "Start" and "End" together
Might throw InterruptedException
Prints "End" before "Start"
Which of the following can be synchronized in Java?
Which object does a synchronized instance method lock on?
How do you synchronize a block of code inside a method?
synchronized(this) { /* code */ }
Which type of lock is acquired when using a static synchronized method?
What is a potential problem with improper synchronization?
Which interface or class in Java provides explicit locking besides synchronized?
What happens if two threads access a non-synchronized method of the same object?
Both can execute concurrently
There are 10 questions to complete.
Take a part in the ongoing discussion
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4