The difference between synchronize and lock? --The difference between wait and sleep?
Enterprise
2023-08-01 20:26:55
views: null
1. The difference between synchronize and lock
- synchronize is a java keyword, lock is a java class
- synchronize is suitable for locking a small part of code, and lock is suitable for locking a large amount of code
- synchronize will automatically release the lock, lock needs to be released manually, otherwise it will deadlock
Two, the difference between wait and sleep
- The scope is different, wait can only be used in synchronize, sleep can be used anywhere
- Different classes, wait comes from Object, sleep comes from Thread
- wait will release the lock, sleep will not release the lock
Origin blog.csdn.net/cst522445906/article/details/121250732