package J20250730.demo02_runnable;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo01_lambdaTestThread
 * @description
 * @create 2025/7/30
 */
public class Demo01_lambdaTestThread {
    public static void main(String[] args) {
        //使用lambda表达式实现runnable接口重写方法
        Runnable run1=()->{
            int sum=0;
            for (int i = 0; i < 10000; i++) {
                //System.out.println(Thread.currentThread().getName()+"-->"+i);
                sum+=i;
            }
            System.out.println(Thread.currentThread().getName()+"的运算结果是："+sum);
        };
        Runnable run2=()->{
            int sum=0;
            for (int i = 0; i < 1000; i++) {
                //System.out.println(Thread.currentThread().getName()+"-->hello");
                if(i%2==0)
                    sum+=i;
            }
            System.out.println(Thread.currentThread().getName()+"的运算结果是："+sum);
        };

        Thread t1=new Thread(run1,"线程-1");
        Thread t2=new Thread(run2,"线程-2");
        t1.start();
        t2.start();
        int sum=0;
        for (int i = 0; i < 1000; i++) {
            if(i%2!=0)
                sum+=i;
        }
        System.out.println(Thread.currentThread().getName()+"的运算结果是："+sum);
        System.out.println("三个线程运算的结果，相加的最终结果为：");
    }
}
