简体   繁体   English

BoneCP和Netty基础

[英]BoneCP and Netty basics

In order to efficiently use connection pooling via BoneCP while programming a Netty server- where is the correct place for the connection pool and where to get a new connection for that pool? 为了在对Netty服务器进行编程时通过BoneCP有效地使用连接池,连接池的正确位置在哪里以及该池的新连接在哪里?

At a glance- I'm thinking that BoneCP should be some sort of global/singleton initialized just once in the main server, and then each handler (ie the class passed as "handler" to the pipeline) references that singleton to grab a new connection... but I don't see any examples of that on the net and, being new to Java, I'm a little concerned to jump right in with that approach. 乍一看-我认为BoneCP应该是在主服务器中初始化一次的某种全局/单例,然后每个处理程序(即,作为“处理程序”传递给管道的类)都引用该单例以获取新的连接...但是我在网络上没有看到任何这样的例子,而且,对于Java的新手来说,我有点担心如何采用这种方法。 Would be great to hear an experienced voice! 听到经验丰富的声音真是太好了!

Yes, a channel handler can very well use the BoneCP connection pool, but you should definitively insert an ExecutionHandler in front of the BoneCP handler. 是的,通道处理程序可以很好地使用BoneCP连接池,但是您必须在BoneCP处理程序的前面明确插入一个ExecutionHandler。 You do not want to issue blocking db calls in a netty IO worker thread. 您不想在netty IO工作线程中发出阻塞的数据库调用。

There's also this defined in bonecp: bonecp中也定义了以下内容:

public ListenableFuture getAsyncConnection(){ 公共ListenableFuture getAsyncConnection(){

    return this.asyncExecutor.submit(new Callable<Connection>() {

        public Connection call() throws Exception {
            return getConnection();
        }});
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM