javamultithreadingthreadgroup

How to create a thread without ThreadGroup?


This question was asked in an interview for the Senior Developer Role. As I don't have any exposure to Java multi-threading and concurrency. So, I could not answer this.

Every thread we create is part of a ThreadGroup. Then how do we create a thread without ThreadGroup?


Solution

  • It is not possible to create a thread without ThreadGroup.

    For more details look here: https://www.eg.bucknell.edu/~mead/Java-tutorial/essential/threads/group.html

    "If you create a new Thread without specifying its group in the constructor, the runtime system automatically places the new thread in the same group as the thread that created it (known as the current thread group and the current thread, respectively). So, if you leave the thread group unspecified when you create your thread, what group contains your thread?

    When a Java application first starts up, the Java runtime system creates a ThreadGroup named main. Unless specified otherwise, all new threads that you create become members of the main thread group."

    And here: http://www.java2s.com/example/java-book/thread-group.html