如何使用WriteLock
一个static
方法?这就是我所拥有的:
m_unitLock = new ReentrantReadWriteLock();
m_unitReadLock = m_unitLock.readLock();
m_unitWriteLock = m_unitLock.writeLock()
static List<unit> units = new ArrayList<Unit>();
...
public static addUnit(){
m_unitWriteLock.lock(); // can not use this inside a static method
units.add(unit);
m_unitWriteLock.unlock();
}
m_unitWriteLock
定义为静态的正确方法吗?你对这种情况有什么建议?tnx。