Biblioteca Java - Blame information for rev 28

Subversion Repositories:
Rev:
Rev Author Line No. Line
28 mihai 1 /*
2  * JoinTest.java
3  */
4 package exemple.fire.join;
5  
6 /**
7  * Class created by @author Mihai HULEA at Feb 22, 2005.
8  *
9  * This class is part of the labs project.
10  *
11  * Programul exemplifica utilizarea metodei join(). In momentul in care un fir de executie
12  * apeleaza metoda join() acesta este blocat pana la terminarea executie firul de executie
13  * pentru care s-a apelat join().
14  *
15  */
16 class JoinTest extends Thread
17 {
18         String n;
19         Thread t;
20         JoinTest(String n, Thread t)
21         {
22                 this.n = n;
23                 this.t=t;
24         }
25  
26         public void run()
27         {
28                 System.out.println("Firul "+n+" a intrat in metoda run()");
29                 try
30                 {                      
31                         if (t!=null) t.join();
32                         System.out.println("Firul "+n+" executa operatie.");
33                         Thread.sleep(3000);
34                         System.out.println("Firul "+n+" a terminat operatia.");
35                 }
36                 catch(Exception e){e.printStackTrace();}       
37  
38         }
39  
40 public static void main(String[] args)
41 {
42         JoinTest w1 = new JoinTest("Proces 1",null);
43         JoinTest w2 = new JoinTest("Proces 2",w1);
44         w1.start();
45         w2.start();
46 }
47  
48 }