BeeOP 0.6 发布,代码重构后优化

栏目: 软件资讯 · 发布时间: 4年前

内容简介:小蜜蜂对象池是一款轻量级Java池化工具 坐标(Java7) <dependency> <groupId>com.github.chris2018998</groupId> <artifactId>beeop</artifactId> <version>0.6</version> </dependency> 更新内容...

小蜜蜂对象池是一款轻量级 Java 池化工具

  坐标(Java7)

<dependency>
   <groupId>com.github.chris2018998</groupId>
   <artifactId>beeop</artifactId>
   <version>0.6</version>
</dependency>

更新内容

1:优化对象接口反射调用

2:对象句柄中增加无参调用方法

3:增加方法调用屏蔽处理(比如原生对象上的关闭方法,配置后可阻止用户对原生对象发起关闭)

项目地址

国内地址: https://gitee.com/mirrors/BeeOP

国外地址: https://github.com/Chris2018998/BeeOP

参考例子1

//定义接口
public interface Book {
    public String getName();
    public long getNumber();
}
//定义对象
public class JavaBook implements Book{
    private String name;
    private long number;
    public JavaBook() {
        this("Java核心技术·卷2", System.currentTimeMillis());
    }
    public JavaBook(String name, long number) {
        this.name = name;
        this.number = number;
    }
    public String getName() {
        return name;
    }
    public long getNumber() {
        return number;
    }
    public String toString() {
        return name;
    }
}
//定义对象工厂
public class JavaBookFactory implements BeeObjectFactory {
    public Object create(Properties prop) throws BeeObjectException {
        return new JavaBook("Java核心技术·卷1", System.currentTimeMillis());
    }
    public void setDefault(Object obj) throws BeeObjectException { }
    public void reset(Object obj) throws BeeObjectException { }
    public void destroy(Object obj) { }
    public boolean isAlive(Object obj, long timeout) {
        return true;
    }
}
//测试代码
public class TestBookPool{
  public static void main(String[]){
      BeeObjectSourceConfig config = new BeeObjectSourceConfig();
      config.setObjectFactory(new JavaBookFactory());
      config.setObjectInterfaces(new Class[]{Book.class});
      BeeObjectSource obs = new BeeObjectSource(config);
      
      BeeObjectHandle handle = null;
      try {
           handle = obs.getObject();
           Object v=handle.call("getName");
           System.out.println("Book name:"+v);
          
          /**
           * 或者这样使用
           * Book book = (Book)handle.getProxyObject();
           * System.out.println(book.getName());
           */
       } catch (BeeObjectException e) {
       } finally {
           if (handle != null)
               handle.close();
       }
    }
}

参考例子2

 Influxdb客户端池化例子

https://my.oschina.net/u/3918073/blog/4958402


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Beginning ARKit for iPhone and iPad

Beginning ARKit for iPhone and iPad

Wallace Wang / Apress / 2018-11-5 / USD 39.99

Explore how to use ARKit to create iOS apps and learn the basics of augmented reality while diving into ARKit specific topics. This book reveals how augmented reality allows you to view the screen on ......一起来看看 《Beginning ARKit for iPhone and iPad》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具