Friday, August 4, 2023

Thread class in Java - 1

 Java Thread Programs

1. Dealing with main

class T1Demo

{

public static void main(String args[])

{

Thread t=Thread.currentThread();

System.out.println("current "+t);

System.out.println(t.getName());

t.setName("MyMain");

System.out.println("current now "+t);

System.out.println(t.getName());

try

{

for(int i=0;i<10;i++)

{

System.out.println(i);

Thread.sleep(1000);

}

}

catch(InterruptedException e)

{

System.out.println("caught");

}

}

}

o/p: --------------------------------------------------------------------------------------------

ddmc@ddmc-desktop:~$ java T1Demo

current Thread[main,5,main]

main

current now Thread[MyMain,5,main]

MyMain

0

1

2

3

4

5

6

7

8

9

In [main, 5, main], 5 is the priority of the thread, the last main is the group name of the thread.

No comments:

Post a Comment

A physicist confesses that the electron is round and that Jesus rose from the dead. (Bengali)

একজন পদার্থবিজ্ঞানী স্বীকার করেন যে ইলেকট্রন গোলাকার এবং যিশু মৃতদের মধ্য থেকে পুনরুত্থিত হয়েছিলেন। আমার নিজের বিশ্বাস প্রমাণ দ্বারা প্রভাব...