Do not use Runnable as a callback; this can be confusing: people and code quality tools sometimes expect them to be used only with threads.
I myself used Runnable as a callback - I thought it looked quite suitable for use as a general callback. A month later, someone found that my code was disabled:
doneCallback.run();
and he noticed that doneCallback was Runnable , and that calling .run() directly caused a warning in our code quality analysis program (Sonar). So, to fix the warning ?, or because he thought the goal was to create a thread ?, he forked a new thread and called run() through that thread.
However, unrolling the flow, he broke the material.
To avoid confusion, I now instead create a common callback interface that has nothing to do with threads. I just add the Callback class using the call method. I think I better not use java.util.concurrent.Callback , because this is also thread related.
KajMagnus May 12 '15 at 6:53 2015-05-12 06:53
source share