Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which line rests on a mistaken assumption?

public class Sample61
{
    public static void main(String[] args) throws Exception
    {
        Thread t = new Thread(() -> { assert false : "worker"; });
        t.start();
        t.join();
        System.out.println("main finished");
    }
}

  • A.Thread t = new Thread(() -> { assert false : "worker"; });
  • B.t.join();
  • C.System.out.println("main finished");
  • D.Nothing here is wrong.

Answer: A

An AssertionError thrown inside a worker thread kills only that thread. join returns normally, main prints and exits with a success status, and the failure is easy to miss in the log. An assertion is only as useful as the thread that reports it, so worker threads need their own handler.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.