How long will the thread live in java?

I create a stream using

Thread t = new Thread();
t.start();

You start the stream using t.start (); Now, how long will the stream live? In what state will it go after X (answer to the indicated question) seconds?

Thread t = new Thread();
t.start();
public void run(){
    System.out.println("Threads");
}

What happens if a thread has a run () method?

+1
source share
1 answer

The created and launched thread, exactly as you describe, will be available only until the empty method Thread.run()does nothing and returns. When the thread completes, the function t.isAlive()will return false.

Usually a thread does something useful and will be alive until the method run()returns.

+2
source

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


All Articles