2

为了在编写 Netty 服务器时通过 BoneCP 有效地使用连接池 - 连接池的正确位置在哪里以及从哪里获得该池的新连接?

一目了然-我认为 BoneCP 应该是某种全局/单例,仅在主服务器中初始化一次,然后每个处理程序(即作为“处理程序”传递给管道的类)引用该单例以获取新的连接......但我在网上没有看到任何这样的例子,而且作为 Java 新手,我有点担心直接采用这种方法。听到有经验的声音会很棒!

4

2 回答 2

1

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. You do not want to issue blocking db calls in a netty IO worker thread.

于 2012-10-25T11:48:51.660 回答
0

在bonecp中也定义了这个:

公共 ListenableFuture getAsyncConnection(){

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

        public Connection call() throws Exception {
            return getConnection();
        }});
}
于 2012-11-10T17:29:06.580 回答