package thead.start.thread_9;


import thead.start.Box;

public class MyThread extends Thread {
    /**
     * If this thread was constructed using a separate
     * {@code Runnable} run object, then that
     * {@code Runnable} object's {@code run} method is called;
     * otherwise, this method does nothing and returns.
     * <p>
     * Subclasses of {@code Thread} should override this method.
     *
     * @see #start()
     */
    @Override
    public void run() {
        super.run();
        try {
            for (; ; ) {
                if (this.isInterrupted()) {
                    throw new InterruptedException("线程中断！");
                }

                for (int i = 0; i < 10000; i++) {
                    String a = "" + Math.random();
                }
                Box.list1.add("生产数据A");
                System.out.println("list1 size=" + Box.list1.size());
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        try {
            while (true) {
                if (this.isInterrupted()) {
                    throw new InterruptedException("线程中断！");
                }

                for (int i = 0; i < 10000; i++) {
                    String a = "" + Math.random();
                }

                Box.list2.add("生产数据B");
                System.out.println("list2 size=" + Box.list2.size());
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
