Threads in Java — Part 4 (Thread Class Constructors)

Java thread class can have 8 constructors with its default constructor.

Here, the “printer” is our example runnable target that we have discussed on our previous articles. In the 8 th way you can see it has special characteristic called stack size in its constructor. As we discussed in our JVM articles, the stack of memory area is responsible to hold the method information as well variable information. So, when JVM creates a thread, it makes a frame in side of stack and assign. That is why a thread can get a stack size.

Following shows declarations for each of 8 ways as mentioned above respectively.

When we create a Thread Group with our program, it allows to manipulate multiple threads with the single commands.

Hope you can get a clear idea about how can we declare thread class constructors in different manners.

Associate Software Engineer at Virtusa.