Let assume, I have some resource and time-consuming code, which I want to arrange as a separate method. In order to optimize the performance, this code should be executed in the separate thread.
Now the question, where to define this thread:
- Inside (built-in) of this «heavy» method;
- Or to wrap the execution of this «heavy» class's code by the thread.
In other words, from the design and the best practice point of view, should I built-in the separate thread execution or it is better to write this code without threads and if there is a need to execute this code in the separate thread, the developer will wrap it by the separate thread?
Update:
The main reason I ask this question is that I want to provide a turnkey solution, which can used as a plug-and-play black box, and not to worry if the end-user will forget to execute this code in the separate thread.