12/27/2023 0 Comments Java deadlock with 1 bject![]() ![]() If (UnLockTest.a1.tryAcquire(1, TimeUnit. Public static final Semaphore a2 = new Semaphore(1) Public static final Semaphore a1 = new Semaphore(1) The case can not obtain, the general is to repeat the attempt, or specify the number of attempts, you can exit immediately. The semaphore can specify a timeout to get, we can according to the time-out, do an extra treatment. ![]() Semaphore can control how many threads can access resources, we specify here can only be one thread access, you do a similar lock. To solve this problem, we do not use to display the locks, we use semaphores to control. deadlock Star Here are 38 public repositories matching this topic. (new Date().toString() + " LockB 锁住 obj1") (new Date().toString() + " LockB 锁住 obj2") (new Date().toString() + " LockA 锁住 obj2") (new Date().toString() + " LockA 锁住 obj1") If improper use of locks, and the screen at the same time when you want to lock multiple objects, there will be a deadlock situation, as follows: Solution to the deadlock problem is: one is synchronized, one is to use explicit locks for Lock. Use the following code to simulate what java deadlock produce. Of course, if the case of a deadlock to break any of these conditions, you can let the deadlock disappear. When these four conditions are fulfilled, then a deadlock.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |