void stop()
Stops automatic metric collection.
Signals the background thread to stop and waits for it to finish.