Java a code locking scheme consultation

demand
FooService:

  • methodA
  • methodB
  • methodC

An and B / C are mutually exclusive, that is, they cannot operate at the same time, but B and C can operate at the same time

obviously synchronized does not support it because it is mutually exclusive

- synchronized void methodA
- synchronized void methodB
- synchronized void methodC

A solution
adopt read-write locks as follows

private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();

public void methodA() {
    rwl.writeLock().lock();
    // do something here
    rwl.writeLock().unlock();
}


public void methodB() {
    rwl.readLock().lock();
    // do something here 
    rwl.readLock().unlock();
}

I don"t know that there is no other solution in Java that can meet the above requirements, that is, one method is mutually exclusive with other methods, but whether the other methods can operate at the same time
or can only use read-write locks

.
Mar.16,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35fe4-40566.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35fe4-40566.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?