class mythread implements Runnable
{
Thread t;
public mythread(String title)
{
t=new Thread(this,title);
t.start();
}
public void run()
{
for(int i=0;i<50;i++)
{
System.out.println((i+1)+"ThreadName:"+Thread.currentThread().getName());
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}}}
public class slip18
{
public static void main(String a [])
{
System.out.println("ThreadName:"+Thread.currentThread().getName());
mythread mt=new mythread("Hello Java");
}
}
/*
OUTPUT
---------------------------------------------------------------
D:\ROHAN\Semester\sem 6>javac slip18.java
D:\ROHAN\Semester\sem 6>java slip18
ThreadName:main
1ThreadName:Hello Java
2ThreadName:Hello Java
3ThreadName:Hello Java
4ThreadName:Hello Java
5ThreadName:Hello Java
6ThreadName:Hello Java
7ThreadName:Hello Java
8ThreadName:Hello Java
9ThreadName:Hello Java
10ThreadName:Hello Java
11ThreadName:Hello Java
12ThreadName:Hello Java
13ThreadName:Hello Java
14ThreadName:Hello Java
15ThreadName:Hello Java
16ThreadName:Hello Java
17ThreadName:Hello Java
18ThreadName:Hello Java
19ThreadName:Hello Java
20ThreadName:Hello Java
21ThreadName:Hello Java
22ThreadName:Hello Java
23ThreadName:Hello Java
24ThreadName:Hello Java
25ThreadName:Hello Java
26ThreadName:Hello Java
27ThreadName:Hello Java
28ThreadName:Hello Java
29ThreadName:Hello Java
30ThreadName:Hello Java
31ThreadName:Hello Java
32ThreadName:Hello Java
33ThreadName:Hello Java
34ThreadName:Hello Java
35ThreadName:Hello Java
36ThreadName:Hello Java
37ThreadName:Hello Java
38ThreadName:Hello Java
39ThreadName:Hello Java
40ThreadName:Hello Java
41ThreadName:Hello Java
42ThreadName:Hello Java
43ThreadName:Hello Java
44ThreadName:Hello Java
45ThreadName:Hello Java
46ThreadName:Hello Java
47ThreadName:Hello Java
48ThreadName:Hello Java
49ThreadName:Hello Java
50ThreadName:Hello Java
---------------------------------------------------------------
*/
No comments:
Post a Comment