Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.64 KB | None | 0 0
  1.     public static void main(String[] args) throws InterruptedException {
  2.        
  3.         new Thread() {
  4.             @Override
  5.             public void run() {
  6.                 try ( Scanner scan = new Scanner( System.in ) ) {
  7.                     for ( String line; (line = scan.nextLine()) != null; ) {
  8.                         System.out.println( "Thread got from console: " + line );
  9.                     }
  10.                 }
  11.             }
  12.         }.start();
  13.        
  14.        
  15.         for( int i = 0;; i++ ) {
  16.             System.out.println( "printing " + i + " in main thread." );
  17.             Thread.sleep( 1000 );
  18.         }
  19.        
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement