zoukankan      html  css  js  c++  java
  • apollo更新bean的属性

    public class FileRefTest {
    
    
        static class Lbw{
            private String name;
    
            public String getName() {
                return name;
            }
    
            public void setName(String name) {
                this.name = name;
            }
        }
        @Test
        public void test() throws NoSuchFieldException, IllegalAccessException, InterruptedException, InstantiationException {
    //        Lbw lbw = new Lbw();
    //        Class<? extends Lbw> aClass = lbw.getClass();
    //        Field filed = aClass.getDeclaredField("name");
    //
    //        aClass.getFields();
    //        lbw.setName("test123");
    
    
            ScheduledExecutorService scheduleExecutor = Executors.newScheduledThreadPool(2);
            Class<?> clazz = Lbw.class;
    
            Field field = null;
            field = clazz.getDeclaredField("name");
            field.setAccessible(true);
    
            Lbw bean = (Lbw) clazz.newInstance();
            field.set(bean, "newVal");
    
            Field finalField = field;
            scheduleExecutor.scheduleAtFixedRate(()->{
                String mySourceFileName = "f://test.txt";
                byte[] bytes = new byte[1024];
                ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
                boolean accessible = finalField.isAccessible();
                finalField.setAccessible(true);
                finalField.setAccessible(accessible);
                
                try (FileChannel inputChannel = new FileInputStream(new File(mySourceFileName)).getChannel();
                ){
    
                    while (inputChannel.read(byteBuffer) > 0) {
                        byteBuffer.flip();
                        String str = new String(bytes, "utf-8");
                        System.out.println(str);
                        byteBuffer.clear(); // 清空buffer
                        finalField.set(bean, str);
                        System.out.println("bean.getName()---"+bean.getName());
                    }
    
                } catch (Exception e) {
    
                }
                System.out.println("======");
            }, 2, 2, TimeUnit.SECONDS);
            CountDownLatch countDownLatch = new CountDownLatch(1);
            countDownLatch.await();
        }
    
    
    }
    
    
  • 相关阅读:
    基于统计语言模型的分词方法
    隐马尔可夫模型(五)——隐马尔可夫模型的解码问题(维特比算法)
    6. D3DXMatrixOrthoLH +正交投影矩阵
    4. Triangle
    顶点坐标变换(D3DXMatrixOrthoLH, D3DXMatrixPerspectiveFovLH)
    7. 透视投影矩阵
    8. 世界矩阵使物体移动
    D3D中的世界矩阵,视图矩阵,投影矩阵
    9. 视图矩阵(摄像机)
    5. Quad
  • 原文地址:https://www.cnblogs.com/kltsee/p/15513628.html
Copyright © 2011-2022 走看看