package ru.agolovin;

/**
 * @author agolovin (agolovin@list.ru)
 * @version $Id$
 * @since 0.1
 */

public class StringParse {

    /**
     * Incoming string.
     */
    private String str;

    /**
     * Constructor.
     *
     * @param str String.
     */
    StringParse(String str) {
        this.str = str;
    }

    /**
     * Main nethod.
     *
     * @param args String array
     */
    public static void main(String[] args) {
        String str = "word word2      word3";
        System.out.println(String.format("Incoming string: %s", str));
        StringParse stringParse = new StringParse(str);
        new Thread(stringParse.new CountWords()).start();
        new Thread(stringParse.new CountWhiteSpace()).start();


    }

    /**
     * Show whiteSpaces count in the String
     */
    public class CountWhiteSpace implements Runnable {
        @Override
        public void run() {
            int count = str.replaceAll("\\S+", "").toCharArray().length;
            System.out.println(String.format("Whitespace count: %s", count));
        }

    }

    /**
     * Show word count in the String.
     */
    public class CountWords implements Runnable {
        @Override
        public void run() {
            int count = str.split("\\s+").length;
            System.out.println(String.format("Words count: %s", count));
        }
    }

}

@@ -483,16 +483,53 @@
 word3%22;%0A
+        System.out.println(%22Start%22);%0A
         
@@ -646,32 +646,51 @@
 se(str);%0A       
+ Thread threadOne =
  new Thread(stri
@@ -718,82 +718,1249 @@
 s())
-.start();%0A        new Thread(stringParse.new CountWhiteSpace()).start();%0A%0A
+;%0A        Thread threadTwo = new Thread(stringParse.new CountWhiteSpace());%0A        long startTime = System.currentTimeMillis();%0A        threadOne.start();%0A        try %7B%0A            threadOne.join(200);%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        threadTwo.start();%0A        try %7B%0A            threadTwo.join(200);%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        while (threadOne.isAlive() %7C%7C threadTwo.isAlive()) %7B%0A            if ((threadOne.isAlive() %7C%7C threadTwo.isAlive()) && (startTime - System.currentTimeMillis() %3C 1000)) %7B%0A                if (threadOne.isAlive()) %7B%0A                    stopThread(threadOne);%0A                %7D%0A%0A                if (threadTwo.isAlive()) %7B%0A                    stopThread(threadTwo);%0A                %7D%0A            %7D%0A        %7D%0A        System.out.println(%22Finish%22);%0A    %7D%0A%0A    /**%0A     * @param thread Thread%0A     */%0A    private static void stopThread(Thread thread) %7B%0A        thread.interrupt();%0A        if (thread.isInterrupted()) %7B%0A            try %7B%0A                throw new InterruptedException();%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D
 %0A   

add task2 in part1 chapter7 package2