Is it a good idea to start a thread from your own constructor?

Is it possible to call the thread_object.start()same object from the constructor?

Is this approach a good idea?

+3
source share
5 answers

You can do it, but this is considered bad practice. There is one paragraph about the beginning of Threads in the constructors in this article .

AS nicerobot stated in the comments, it seems your question is a duplicate of this . Look at the Heath Borders answer there.

+6
source

- ? Runnable , (, , , ExecutorService, ).

+2

, , . start() , .

, - :

1: MyObject(){
2:  aVariable = anyValue;
3:  this.start();
4: }

3 2, ( ), ( ) .

+1

, , . .

0

, , this, . this ( ), , , .

-1

Source: https://habr.com/ru/post/1744315/


All Articles