chapter_005/src/main/java/ru/job4j/switcher/Switcher.java
/**
     * Create 2 threads.
     * Threads alternately insert 10 elements in the line.
     */
Create 2 threads.
Threads alternately insert 10 elements in the line.
Create 2 threads . Threads alternately insert 10 elements in the line .
public void play() {
        Thread thread1 = new Thread(() -> {
            int number = rd.nextInt(10);
            while (starting) {
                addNumber(number);
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    break;
                }
            }
        });
        Thread thread2 = new Thread(() -> {
            int number = rd.nextInt(10);
            while (starting) {
                addNumber(number);
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    break;
                }
            }
        });
        thread1.start();
        thread2.start();
    }
public void play ( ) { Thread thread1 = new Thread ( ( ) -> { int number = rd . nextInt ( 10 ) ; while ( starting ) { addNumber ( number ) ; try { Thread . sleep ( 50 ) ; } catch ( InterruptedException e ) { break ; } } } ) ; Thread thread2 = new Thread ( ( ) -> { int number = rd . nextInt ( 10 ) ; while ( starting ) { addNumber ( number ) ; try { Thread . sleep ( 50 ) ; } catch ( InterruptedException e ) { break ; } } } ) ; thread1 . start ( ) ; thread2 . start ( ) ; }
Create 2 threads.
Create 2 threads .