-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynchroThread.java
More file actions
65 lines (63 loc) · 972 Bytes
/
synchroThread.java
File metadata and controls
65 lines (63 loc) · 972 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class threadSynchro extends Thread
{
public void printThread(int n)
{
for (int i = 1; i <= 10; i++)
{
System.out.println("Thread " + n
+ " is working...");
try
{
Thread.sleep(600);
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
}
System.out.println("--------------------------");
try
{
Thread.sleep(1000);
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
}
}
class Thread1 extends Thread
{
threadSynchro test;
Thread1(threadSynchro p)
{
test = p;
}
public void run()
{
test.printThread(1);
}
}
class Thread2 extends Thread
{
threadSynchro test;
Thread2(threadSynchro p)
{
test = p;
}
public void run()
{
test.printThread(2);
}
}
public class synchroThread
{
public static void main(String[] args)
{
threadSynchro p = new threadSynchro();
Thread1 t1 = new Thread1(p);
Thread2 t2 = new Thread2(p);
t1.start();
t2.start();
}
}