Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Thread Constructors

In this section, you will learn about the different types of thread constructors.


Threading In Java Example Thread Life Cycle Example in java What Is Thread In Java? Creating multiple Threads Daemon Threads Synchronization in java with example Thread priority in java Threads in Java Java Multithreading Example Thread Synchronization in Java Overview of Networking through JAVA,How to retrieve URL information URL in term of Java Network Programming Overview of Networking through JAVA,Convert URI to URL Socket and ports Server Sockets Overview of Networking through JAVA,Find the Host name in reverse of given IP address Print the URL of a URLConnection Networking in Java Computer Networking Overview of Networking through JAVA,Getting the Local port Overview of Networking through JAVA Overview of Networking through JAVA Overview of Networking through JAVA,Getting list of Local Interfaces on a machine Overview of Networking through JAVA Overview of Networking through JAVA,Find Your Host Name Overview of Networking through JAVA,To retrieve the IP address from Host Name, vice-versa Open a URLConnection to specific website address Return the MIME Header Construct a DatagramSocket on an unspecified port Datagram in network environment Construct a DatagramPacket to receive data Client-Server Architecture Thread Priorities Synchronized Threads Multithreading in Java Interthread Communication Creation of MultiThreads Threading in Java Thread Priorities Inter-Thread Communication Synchronized Threads Creation of Multiple Threads Threading in Java Daemon Threads Deadlock Synchronization Life Cycle of Threads Thread Constructors Thread Creation Overview of Thread

Thread Constructors


Several constructors are available for creating new Thread instances.








Thread(ThreadGroup, Runnable, String, long)


ThreadGroup? All threads belongs to an instance of the ThreadGroup Class. ThreadGroup is used to represent a group of threads. ThreadGroups can be shown in a hierarchical manner. There is only one root ThreadGroup that contains all other thread and groups and each subgroups can contain other groups and threads. All thread have only one thread group. And all thread groups (except the root thread group) belongs to exactly one parent thread group. Threads can access only belonging thread group.

When a new ThreadGroup is created, it is added as a member of existing ThreadGroup.
If a thread x in group1, and executes the code:

  ThreadGroup group2=new ThreadGroup(?group2?);

Then the newly formed group2 comes under group1. If you want a parent group other than default then you have to specify the parent group at the time of creation.

  ThreadGroup group2=new ThreadGroup(group2,?group3?);

Then newly formed group3 comes under the group2.

Some important methods are:

  • getName() ? This method is used to retrieve the name of particular group.

    ThreadGroup g=new ThreadGroup(?RoseIndia?);
      String gname=g.getName();


  • getParent() ? This method is used to retrieve the name of parent threadgroup of sub group.

  •    ThreadGroup group=group3.getParent();


  • activeGroupCount() ? This method returns the number of active thread group in a particular thread group and all its subgroups.

       int size=group.activeGroupCount();


  • getThreadGroup() ? This method is used to know the thread is belong to which thread group.

    ThreadGroup group=threadx.getThreadGroup();



Share on Google+Share on Google+

Thread Constructors

Posted on: April 17, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Thread Constructors   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
September 12, 2011

Sir, I had a doute abt threads, my doute is is thread constuctor is having 2 params 1 is thread or runnable and why the String param is used.......
April 4, 2012

how to start and stop a thread if there is only a single thread in the program, apart from main thread?