Tranvick

test

May 28th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package __SERVER;
  2.  
  3.  
  4. public class Server {
  5.     public static void main(String[] args) {
  6.         ThreadB b = new ThreadB();
  7.         b.start();
  8.    
  9.         synchronized (b) {
  10.             try {
  11.                 System.out.println("Ждем пока поток b выполнится...");
  12.                 b.wait();
  13.             } catch (InterruptedException e) {
  14.             }
  15.    
  16.             System.out.println("Total равно: " + b.total);
  17.         }
  18.     }
  19.    
  20.     private static class ThreadB extends Thread {
  21.         int total;
  22.        
  23.         public void run() {
  24.             synchronized (this) {
  25.                 for (int i = 0; i < 100; i++) {
  26.                     total += i;
  27.                 }
  28.                 notifyAll();
  29.                 try {
  30.                     sleep(10000);
  31.                 } catch (InterruptedException e) {
  32.                     e.printStackTrace();
  33.                 }
  34.             }
  35.         }
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment