Class A generates random integers between -100 and 100 at a random frequency between 0 and 2 seconds. Class B decrements a counter when class A generated a negative integer and increments when class A generated a positive integer. Class B's counter needs to be updated in real time as class A generates numbers. 
Show Java code when A and B are different threads.

解决方案 »

  1.   

    I think that the question can be resolved quickly after jdk1.5. Java supply BlockingQueue interface at 1.5,BlockingQueue implementations are thread-safe.so you can use thread1 to put the value in it, and take the value in thread2. when the queue is empty, it will blocking. the detail content can reference to the jdk1.5 api.
      

  2.   

    why don't do that with one thread and read the integer with another thread?
      

  3.   

    it's an typical producer-consumer scenario,so use concurrent.BlockingQueue 
      

  4.   

    correct, producer and consumer