@@ -0,0 +1,2689 @@
+package ru.job4j.threads;%0A%0A/**%0A * class CalculateChars.%0A */%0Apublic class CalculateChars %7B%0A    /** time.*/%0A    private static int time = 0;%0A%0A    /**%0A     * method start.%0A     * @param str - incoming string.%0A     * @param timeToStop - stop time.%0A     * @throws InterruptedException - exception.%0A     */%0A    private static void start(String str, int timeToStop) throws InterruptedException %7B%0A        System.out.println(%22Start%22);%0A        Thread threadTime = new Thread(new TimeCalc());%0A        Thread threadCalc = new Thread(new CharCalc(str));%0A        threadTime.start();%0A        threadCalc.start();%0A        while (time %3C timeToStop) %7B%0A            Thread.sleep(100);%0A        %7D%0A        threadTime.interrupt();%0A        threadCalc.interrupt();%0A        System.out.println(%22Finish%22);%0A    %7D%0A%0A    /**%0A     * method main.%0A     * @param args - args.%0A     * @throws InterruptedException - exception.%0A     */%0A    public static void main(String%5B%5D args) throws InterruptedException %7B%0A        String str = %22Some text with some sense for something%22;%0A        int timeToStop = 1000;%0A        start(str, timeToStop);%0A    %7D%0A%0A    /**%0A     * class TimeCalc.%0A     */%0A    static class TimeCalc implements Runnable %7B%0A        /**%0A         * method run.%0A         */%0A        @Override%0A        public void run() %7B%0A            long startTime = System.currentTimeMillis();%0A            Thread thread = Thread.currentThread();%0A            while (!thread.isInterrupted()) %7B%0A                time = (int) (System.currentTimeMillis() - startTime);%0A                try %7B%0A                    Thread.sleep(100);%0A                %7D catch (InterruptedException e) %7B%0A                    System.out.println(%22Time thread is interrupted%22);%0A                    return;%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    /**%0A     * class CharCalc.%0A     */%0A    static class CharCalc implements Runnable %7B%0A        /** string.*/%0A        private String string;%0A%0A        /**%0A         * constructor.%0A         * @param string - incoming string.%0A         */%0A        CharCalc(String string) %7B%0A            this.string = string;%0A        %7D%0A%0A        /**%0A         * method run.%0A         */%0A        @Override%0A        public void run() %7B%0A            int sum = 0;%0A            for (int i = 0; i %3C string.length(); i++) %7B%0A                if (string.charAt(i) != ' ') %7B%0A                    sum++;%0A                %7D%0A                try %7B%0A                    Thread.sleep(10);%0A                %7D catch (InterruptedException e) %7B%0A                    System.out.println(%22CharCalc thread is interrupted%22);%0A                    return;%0A                %7D%0A            %7D%0A            System.out.println(String.format(%22Sum of char in string - %25s%22, sum));%0A        %7D%0A    %7D%0A%7D

task 1019 programm stop