zoukankan      html  css  js  c++  java
  • WebFlux的初步学习

    下个项目可能会用吧

    1. Lambda表达式要熟悉
    2. 函数式接口 https://www.runoob.com/java/java8-functional-interfaces.html
    3. 方法,变量的引用
    4. 级联表达式和柯里化
    5. stream流水线编程
    6. webFlux的优势,劣势

    1 .  lambda表达式的作用是生成自定义接口的实例对象

    2.  一个标准的函数式接口由@FunctionalInterface + 唯一的抽象方法 + 一些default , static 修饰的方法

        常用: 

    Predicate       T        boolean         断言
    Consumer        T        /               消费一个参数
    Supplier        /        T               提供者
    UnaryOperator   T     T                  一元函数,输出输入类型一致
    Function        T        R               输入输出类型可以不一致
    BiFunction      T,T    R                 两个参数
    BInaryOperator  T,T   T                  二元函数
    

     3. 静态方法, 构造方法,实例方法

           lambda表达式的中内部类引用外部变量, jdk8默认外部变量添加了final修饰.

           因为java是值传递, 内外变量指向同一个值.

       4. 

        //级联表达式
        Function<Integer, Function<Integer, Integer>> fim =  x -> y -> x + y;
       //柯里化:函数标准化, 将多个参数转化为一个函数
        Integer apply = fim.apply(2).apply(3);
        System.out.println(apply);
    

      5. stream流: 一个迭代器, 不存放数据

               中间操作 : 返回一个流; map()

               终止操作:  返回一个结果; count()

               惰性求值: 终止操作没有进行调用,中间操作不会进行执行;

        无状态操作: map , flatmap , filter , peek  (map 单纯修改数据, flatmap可以返回数据下使用)

        有状态操作: distinct , sorted , limit / skip

        终止操作:  foreach / foreachOrdered  /  collect /reduce

        并行流: parallel()

       

    	//自定义线程,防止阻塞 
    		ForkJoinPool pool = new ForkJoinPool(8);
    		pool.submit(() -> IntStream.range(0, 100).parallel().peek(StreamDemo4::doing).count());
    		pool.shutdown();
    		//ForkJoinPool 是守护线程需要延长主线程时间
    		try {
    			Thread.sleep(100000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    	public static void doing(int i){
    		System.out.println(Thread.currentThread().getName()+"debug"+":"+i);
    		try {
    			TimeUnit.SECONDS.sleep(3);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    

      收集器:

        public static void main(String[] args) {
            List<Boy> list = Arrays.asList(
                    new Boy(1,170,"一号"),
                    new Boy(1,172,"2号"),
                    new Boy(3,173,"3号"),
                    new Boy(2,174,"4号"),
                    new Boy(3,178,"5号"),
                    new Boy(7,179,"6号"),
                    new Boy(7,181,"7号"),
                    new Boy(7,185,"8号"),
                    new Boy(7,190,"9号")
                    );
            //聚合数据
            List<String> collect = list.stream().map(Boy::getbName).collect(Collectors.toList());
            System.out.println(collect);
            //指定具体类型
            TreeSet<String> set = list.stream().map(Boy::getbName).collect(Collectors.toCollection(TreeSet::new));
            //统计信息
            IntSummaryStatistics collect2 = list.stream().collect(Collectors.summarizingInt(Boy::getbId));
            System.out.println(collect2.toString());
            //分块
            Map<Boolean, List<Boy>> map = list.stream().collect(Collectors.partitioningBy(b -> b.getbHeight() > 180));
            MapUtils.verbosePrint(System.out, "身高分组", map);
            //分组
            Map<Integer, List<Boy>> collect3 = list.stream().collect(Collectors.groupingBy(Boy::getbId));
            Map<Integer, Long> collect4 = list.stream().collect(Collectors.groupingBy(Boy::getbId,Collectors.counting()));
        }
  • 相关阅读:
    vim 常用命令
    centos 安装mysql
    centos部署ftp
    centos 6.8部署nginx
    ndk学习16: unix domain socket
    ndk学习14: 进程
    ndk学习13: proc
    ndk学习11: linux内存管理
    ndk学习10: linux文件系统
    ndk学习9: 动态使用共享库
  • 原文地址:https://www.cnblogs.com/zkfly/p/11613843.html
Copyright © 2011-2022 走看看