How to detect if the db is being compacted in a JAVA agent?

Hi,Does anyone know how can I detect if the currentdatabase is being compacted?

It’s just to avoid the execution of a Java agent when it happens.

Thanks,

Sofia.