jeudi 26 février 2015

Stop background thread when exception is thrown in main thread



I am writing a program in Java that uses a DDS mechanism for messaging that starts its own background threads when writers and the such are created. However if in the main thread an error occurs I throw an exception with the following code.


throw new FooUncheckedException(writerTypes.get(i) + " is not a writer type");


The main thread then terminates like it is supposed to. However, the background threads created by the DDS library I am using continue to run so the program never stops running technically. How would I go about gracefully shutting down the background threads as well that are keeping the program alive?




Aucun commentaire:

Enregistrer un commentaire