I've been using this code for years. I copy and pasted it from someone else on this group, someone much smarter than I am. I have never seen an error from this code. Now suddenly I get a null pointer exception at the last line of this code:
(ns denormalize_mysql_to_mongodb.monitoring
(:import
java.lang.management.ManagementFactory)
(:require [clojure.string :as st]))
(defn thread-top
"Return a seq of threads sorted by their total userland CPU usage."
[]
(let [mgr (ManagementFactory/getThreadMXBean)
cpu-times (map (fn [t]
[(.getThreadCpuTime mgr (.getId t)) t])
(threads))]
(map
(fn [[cpu t]] [cpu (.getName t) (.getId t) t])
(reverse (sort-by first cpu-times)))))
This error is thrown at startup. I don't know much about ThreadMXBean. Can anyone give me a clue why any of this would be nil?