Advertisement
Guest User

Untitled

a guest
Jul 10th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.88 KB | None | 0 0
  1. package Last;
  2.  
  3. import java.util.*;
  4.  
  5. public class aaaa implements Runnable {
  6.        
  7.         Thread t1, t2;
  8.        
  9.         public static void main( String[] args )
  10.         {
  11.             new aaaa( ).go( );
  12.         }
  13.        
  14.         public void go( )
  15.         {
  16.             t1 = new Thread( new aaaa( ) );
  17.            
  18.             t2 = new Thread( new aaaa( ).new bbb( ) );
  19.            
  20.             t1.start( );
  21.            
  22.             t2.start( );
  23.            
  24.         }
  25.        
  26.         public void run( )
  27.         {
  28.             for( int i = 0 ; i < 1000 ; i++ )
  29.             {
  30.                 if( i == 200 )
  31.                 {
  32.                     if( t2.isAlive( ) )
  33.                         t2.interrupt( );
  34.                     }
  35.                
  36.                 System.out.println( "**********" + i+ " **********" );
  37.             }
  38.         }
  39.        
  40.         class bbb implements Runnable {
  41.             public void run( )
  42.             {
  43.                 for( int i = 1000 ; i < 4000 ; i++ )
  44.                 {
  45.                     if( Thread.interrupted ( ) )
  46.                     {
  47.                         System.out.println( "We Have Been Interrupted!!" );
  48.                        
  49.                         return;
  50.                     }
  51.                    
  52.                     System.out.println( i );
  53.                 }
  54.             }
  55.         }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement