Killing Infinite Loops in Java/Clojure
clojure, java, multithreading, slime, swank
Solution
I don't think a fully complete answer exists, though there are some incomplete but still useful things to do:
- First I hit `ctrl-c ctrl-c` from the repl which kills the foreground thread which gets 99% of my common mistakes.
- Then if that fails I go for the terminal and the `kill` command.
- after that its `M-x slime-quit-lisp`, `clojure-jack-in`
Problem
Responses to some "potential answers" You should sprinkle "interrupts" into your threads I don't write my code with the intention of it being a long process / infinite loop; it's just that in development, I accidently write code that happens to be infinite loops, thus I can never plan beforehand to put "check if thread got interrupted" into the code. Question: As I get more familiar with Java/Clojure/Swank and incremental code development. I find it very easy for me to accidentally write a clojure function that ends up being an infinite loop -- and run it. This then goes ahead, and pegs the JVM, causing the fans on my laptop to spin up -- and basically, I have to kill the entire JVM to just get rid of one run away thread. Now, is there anyway I can somehow kill these clojure threads safely? I am well aware that Thread.stop has various unsafe consequences (like holding locks that other threads may need, etc ...) -- however, these here are clojure functions that are infinite looping -- and I'm doing them outside of any STM -- so I'm wondering if there's some way to kill these threads safely. Thanks!