import java.io.File;

/**
 * Created by Vol4ica on 14.06.2015.
 */
public class ManyRecursion{

    File parent;
    long size;
    int number;

    public ManyRecursion(File parent, long size, int number) {
        this.parent=parent;
        this.size = 0;
        this.number = 0;
    }

    public static class MyRunnable implements Runnable{
        @Override
        public void run () {

            synchronized (countSize(parent,size)){}////ÊÀÊ ÑÞÄÀ ÏÅÐÅÄÀÒÜ ÄÀÍÍÛÅ?!
            synchronized (countNumber(parent,number)){}
        }


    public static long addSize(long s1,long s2)
    {
        long s=s1+s2;
        return s;
    }
    public static int addNumber(int n1,int n2)
    {
        int n=n1+n2;
        return n;
    }
    public static long countSize(File parent, long size) {
        File[] files = parent.listFiles();
        for(File f : files) {
            if (f.isFile())
            {
                size = addSize(size, f.length());
            }
            else if (f.isDirectory())
            {
                Thread t = new Thread();
                t.start();
                t.setName(f.getAbsolutePath());
            }
        }
        System.out.println("Size="+size);
        return size;
    }
    public static int countNumber(File parent, int number) {
        File[] files = parent.listFiles();
        for(File f : files) {
            if (f.isFile())
            {
                number = addNumber(number, 1);
            }
            else if (f.isDirectory())
            {
                Thread t = new Thread();
                t.start();
                t.setName(f.getAbsolutePath());
            }
        }
        System.out.println("Number="+number);
        return number;
    }
}
}
