Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
public class Container implements Runnable {
  private final Vector<String> vector = new Vector<String>();
  public Vector<String> getVector() {
    return vector;
  }
  
  public void run() {
    String string = null;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    do {
      System.out.println("Enter another string");
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      try {
        string = in.readLine();
      } catch (IOException e) {
        // Forward to handler
      }
      vector.add(string);
    } while (!"END".equals(string));
  }

  public static void main(String[] args) throws InterruptedException {
    Container c = new Container();
    Thread thread = new Thread(c);
    thread.start();
    Thread.sleep(5000);
    thread.stop();
  }
}

...

Code Block
bgColor#ccccff
public class Container implements Runnable {
  private final Vector<String> vector = new Vector<String>();
  
  private volatile boolean done = false;
  
  public Vector<String> getVector() {
    return vector;
  }
  
  public void shutdown() {
	  done = true;
  }

  public void run() {
    String string = null;
    doBufferedReader {
in = new    System.out.println("Enter another string"BufferedReader(new InputStreamReader(System.in));
    do {
 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)).out.println("Enter another string");
      try {
        string = in.readLine();
      } catch (IOException e) {
        // Forward to handler
      }
      vector.add(string);
    } while (!done && !"END".equals(string));
  }

  public static void main(String[] args) throws InterruptedException {
    Container c = new Container();
    Thread thread = new Thread(c);
    thread.start();
    Thread.sleep(5000);
    c.shutdown();
    return;
  }
}

...

Code Block
bgColor#ccccff
public class Container implements Runnable {
  private final Vector<String> vector = new Vector<String>();
  
  public Vector<String> getVector() {
  	return vector;
  }

  public void run() {
    String string = null;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    do {
      System.out.println("Enter another string");
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      try {
        string = in.readLine();
      } catch (IOException e) {
        // Forward to handler
      }
      vector.add(string);
    } while (!Thread.interrupted() && !"END".equals(string));
  }

  public static void main(String[] args) throws InterruptedException {
    Container c = new Container();
    Thread thread = new Thread(c);
    thread.start();
    Thread.sleep(5000);
    thread.interrupt();
  }
}

...