Share on Google+Share on Google+

Java Thread setName

In this section of java tutorial we will learn about the Java Thread setName() method and its use. Then We will create an example and show its usage.

  • Java Thread setName() method sets the new name to each Thread.
  • It is used in both Thread class and Runnable interface.
  • Name is also set by the string data used in the constructor.

Java Thread setName Example

public class setname implements Runnable {
	public void run() {

	public static void main(String[] args) {
		Thread t1 = new Thread(new setname(), "Thread a");
		Thread t2 = new Thread(new setname());
		t2.setName("Thread b");


Thread[Thread a,5,main] Thread a Thread[Thread b,5,main]


Posted on: November 7, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.