Java反射,多线程

//反射
        /*Class<?> clazz = Class.forName("cn.lpf.threadDemo.ReflectPoint");
        Field fieldx = clazz.getField("x");
        Field fieldy = clazz.getField("y");
        Object obj = clazz.newInstance();
        fieldx.setAccessible(true);
        fieldx.set(obj, 10);
        System.out.println("获取字段:"+fieldx);
        System.out.println("字段的值 x=:"+ fieldx.getInt(obj));
        System.out.println("字段的值 y=:"+fieldy.getInt(obj));
        Method drawCricle = clazz.getMethod("sayHello", String.class);
        
        String str = (String) drawCricle.invoke(obj, "HelloWorld");
        System.out.println(str);
        Method[] methods = clazz.getMethods();
        System.out.println("所有的方法集合");
        for (int i = 0 ; i<methods.length;i++){
            Object[] obj2 = methods[i].getParameterTypes();
            System.out.println("方法名:"+methods[i]);
            for (int j = 0;j<obj2.length ; j++){
                System.out.println(obj2[j]);
            }
        }*/
        //ArrayList
        /*List<String> list = new ArrayList<String>();
        list.add("老公");
        list.add("老婆 ");
        for (String str : list){
            System.out.println(str);
        }
        Map<String,String> map = new HashMap<String,String>() ;
        map.put("lpf", "刘朋飞");
        map.put("lsm", "卢树敏");
        
        */
        /*System.out.println("9*9乘法口决表");
        for ( int i = 1 ; i<=9 ;i++){
            for (int j = 1 ;j<=i ;j++){
                System.out.print(j+"*"+i+"="+(i*j)+"  ");
            }
            System.out.println();
        }*/
        //多线程
        /*Thread thread = new Thread(){
            @Override
            public void run(){
                while (true ){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    new Timer().schedule(new TimerTask(){

                        @Override
                        public void run() {
                            System.out.println(Thread.currentThread().getName());
                            Map<String,Integer> map = new HashMap<String,Integer>() ;
                            map.put("lpf", 10);
                            map.put("lsm", 20);
                            if(map.get("lpf")> 10){
                                System.out.println("刘朋飞的成绩");
                            }
                            else{
                                for ( int i = 1 ; i<=9 ; i++){
                                    for ( int j = 1 ; j<=9; j++){
                                        if (j<=i)
                                            System.out.print(j+"*"+i+"="+(i*j) + "     ");
                                    }
                                    System.out.println();
                                }
                            }
                            System.out.println("\r\n\r\n");
                        }
                    }, 1 , 1);
                }
            }
        };
        thread.start();
        //第二个线程
        Thread thread2 = new Thread(new Runnable() {
            
            @Override
            public void run() {
                while (true ){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    new Timer().schedule(new TimerTask(){

                        @Override
                        public void run() {
                            System.out.println(Thread.currentThread().getName());
                            Map<String,Integer> map = new HashMap<String,Integer>() ;
                            map.put("lpf", 10);
                            map.put("lsm", 20);
                            if(map.get("lpf")> 10){
                                System.out.println("刘朋飞的成绩");
                            }
                            else{
                                for ( int i = 1 ; i<=9 ; i++){
                                    for ( int j = 1 ; j<=9; j++){
                                        if (j<=i)
                                            System.out.print(j+"*"+i+"="+(i*j) + "     ");
                                    }
                                    System.out.println();
                                }
                            }
                            System.out.println("\r\n\r\n");
                        }
                    }, 1 , 1);
                }//Trandition
            }
        });
        thread2.start();
        //第三个线程
        Thread thread3 = new Thread(new Runnable() {
            
            @Override
            public void run() {
                
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                new Timer().schedule(new TimerTask(){

                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName());
                        Map<String,Integer> map = new HashMap<String,Integer>() ;
                        map.put("lpf", 10);
                        map.put("lsm", 20);
                        if(map.get("lpf")> 10){
                            System.out.println("刘朋飞的成绩");
                        }
                        else{
                            for ( int i = 1 ; i<=9 ; i++){
                                for ( int j = 1 ; j<=9; j++){
                                    if (j<=i)
                                        System.out.print(j+"*"+i+"="+(i*j) + "     ");
                                }
                                System.out.println();
                            }
                        }
                        System.out.println("\r\n\r\n");
                    }
                }, 1 , 1);
            }
        }){
        };
        thread3.start();
        
        //第四个线程
        Thread thread4 = new Thread(new Runnable() {
            
            @Override
            public void run() {
                // TODO Auto-generated method stub
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                new Timer().schedule(new TimerTask(){

                    @Override
                    public void run() {
//                        System.out.println(thread4.getName());
                        Map<String,Integer> map = new HashMap<String,Integer>() ;
                        map.put("lpf", 10);
                        map.put("lsm", 20);
                        if(map.get("lpf")> 10){
                            System.out.println("刘朋飞的成绩");
                        }
                        else{
                            for ( int i = 1 ; i<=9 ; i++){
                                for ( int j = 1 ; j<=9; j++){
                                    if (j<=i)
                                        System.out.print(j+"*"+i+"="+(i*j) + "     ");
                                }
                                System.out.println();
                            }
                        }
                        System.out.println("\r\n\r\n");
                    }
                }, 1 , 1);
            }
        });
        thread4.start();*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值