Вот пример с помощью GarbageCollectorMXBean
для распечатывания статистики GC. По-видимому, Вы периодически называли бы этот метод, например, планирующий использование ScheduledExecutorService
.
public void printGCStats() {
long totalGarbageCollections = 0;
long garbageCollectionTime = 0;
for(GarbageCollectorMXBean gc :
ManagementFactory.getGarbageCollectorMXBeans()) {
long count = gc.getCollectionCount();
if(count >= 0) {
totalGarbageCollections += count;
}
long time = gc.getCollectionTime();
if(time >= 0) {
garbageCollectionTime += time;
}
}
System.out.println("Total Garbage Collections: "
+ totalGarbageCollections);
System.out.println("Total Garbage Collection Time (ms): "
+ garbageCollectionTime);
}
That's a tough one. You're still going to have to table scan (or index scan), since YOU have to calculate the new hash and compare it to the old hash stored.
If triggers are not possible because of cross-platform concerns, you might be able to have the database engine calculate the current hash (i.e. persisted computed column - effectively like a trigger). This is also cross-platform problem, though! Then if you index the current hash and your hash, it's a relatively easier search.
Can you at least use the timestamp field to reduce the number of hashes you need to check?
Another thing to remember is that there's no such thing as a perfect hash function, so you could potentially have false negatives (inadvertent hash collision leads to a change not being detected). Is that (astronomically small) risk worth taking?
Я бы стандартизировал то, как ваше приложение проверяет разницу, а не то, как база данных реализует это. Попробуйте что-нибудь вроде использования представления с определенным столбцом, которое означает изменение. Затем используйте соответствующие приемы, реализованные в каждой базе данных, чтобы воплотить это представление в жизнь. Код, зависящий от проверки этой разницы, будет таким же с использованием того же представления и столбца.