Java Thread 课后习题

_**Thread **_
1. Defines a MyStack class, including following attributes and methods:
Attributes:
(1) An array of char type with 5 elements .
(2)Other variables are defined as needed.
Methods:
(1)void push (char c) : push a character in an array .
(2)char pop (): get a character from an array .
**2. Defines two thread classes Producer and Consumer, Producer thread stores 26 **
**English letters in the array of MyStack objects, Consumer thread extracts the 26
letters from the array of the same object. **
3. When all five elements in the array have values, the producer thread needs to wait
for the consumer thread to take the letter, and when the consumer thread takes one
letter, the producer thread can be notified by the consumer thread. On the other
hand, when there are no letters in the array, the consumer thread has to wait for
the producer thread to put the letter, and after the producer puts a letter , it can
notify the consumer thread to take the letter.

4. Define a test class, create an object for two thread classes, and start both threads at
the same time.
Tip: using synchronized, wait() and notify() to synchronize two threads