-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadDemo1.java
More file actions
46 lines (46 loc) · 876 Bytes
/
ThreadDemo1.java
File metadata and controls
46 lines (46 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package Multi_Threading;
class MyThread implements Runnable
{
Thread t1;
MyThread(String Name)
{
t1 = new Thread(this,Name);
System.out.println("Thread1 :"+t1.getName());
t1.start();
}
public void run()
{
try
{
for(int i=0;i<5;i++)
{
System.out.println("Thread1 :"+t1.getName());
System.out.println("Thread1 :"+i);
Thread.sleep(1000);
}
}catch(InterruptedException e)
{
System.out.println(e);
}
}
}
public class ThreadDemo1 {
public static void main(String[] args)
{
Thread t = new Thread();
new MyThread("Thread 1");
try
{
for(int i=0;i<5;i++)
{
System.out.println("Thread2:"+t.getName());
System.out.println("Thread2 :"+(2*i));
Thread.sleep(1000);
}
}catch(InterruptedException e)
{
System.out.println(e);
}
System.out.println();
}
}