특정 criterian이 충족되면 테이블 데이터베이스를 해제하는 서버 서비스가 있습니다. 그것은이잠금 문제 : 일부 브레인 스토밍 제안이 필요합니다.
public static void autoUnloadDbTable(final Configuration conf) {
final String mKey = getMapKey(conf);
final Table table = TABLES.get(mKey);
if (table != null) {
dblock.getLock().lock();
table.instance.dispose();
TABLES.remove(mKey);.....(2)
}
//here release lock when done...
}
처럼 보이는 그러나 위의 기능이
public Table getTableLocked(final Lock lock) throws FactFinderException {
boolean loadTable = true;
// Get the current table instance
Table table = TABLES.get(mapKey);
// .....(1)
if (table != null) {
//do something
}
if (loadTable) table = loadTableLocked(table);
// lock the table, so the instance don't gets replaced
if (lock != null) lock.lock();
return table.instance;
}
에서 (1)
실행되고있을 때 내가 하나 개의 스레드가를 실행하는 경우 때문에 뭔가를 둘 필요가 옆으로 실행할 수있는 다른 작업이있다 코드는 (2)이고 다른 스레드는 이미 테이블 객체를 가지고 있지만 (2)는 테이블 객체를 삭제할 것이므로 (1)을 초과하는 모든 것은 올바른 값을 갖지 않을 것입니다. .. 어떤 제안도 제발 ... ?? 당신이 당신의 테이블을 포장 고려할 수 의견을 바탕으로
당신이 table.instance을 반환 한 후에는, autoUnloadDbTable는 여전히 테이블이라고, 따라서 될 수있다. instance.dispose. – richs