Skip to content

Commit 6c7a4dc

Browse files
committed
notes: added JavaQ68
1 parent 76e00e3 commit 6c7a4dc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

notes/questions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,16 @@ int Integer
766766
> Choice of synchronization though depends upon a number of threads because the number of thread present more contention,
767767
> so you go for advanced synchronization technique e.g. lock stripping, which requires more complex code and expertise.
768768
769+
68. How do you call wait() method? using if block or loop? Why?
770+
> `wait()` method should always be called in loop because it's possible that until thread gets CPU to start running again the condition might not hold, so it's always better to check condition in loop before proceeding, example:
771+
> ```java
772+
> // The standard idiom for using the wait method
773+
> synchronized (obj) {
774+
> while (condition does not hold)
775+
> obj.wait(); // (Releases lock, and reacquires on wakeup)
776+
> ... // Perform action appropriate to condition
777+
> }
778+
> ```
769779
## Spring Boot
770780
1. What is the difference between Java EE and Spring?
771781
> Java EE is standardized (now Jakarta EE), runs on containers like WildFly.<br>

0 commit comments

Comments
 (0)