mysql jdbc netty_netty里集成spring注入mysq连接池(一)

netty的性能非常高,能达到8000rps以上,见

1.准备好需要的jar包

spring.jar//spring包

netty-3.2.4.Final.jar// netty库

commons-dbcp.jar// dbcp数据库连接池

mysql-connector-java-5.1.6.jar// dbcp数据库连接池需要依赖

commons-logging.jar//spring.jar需要依赖

commons-pool.jar// dbcp数据库连接池需要依赖

2.新建java工程TestNettyServer

2.1导入netty的例子

HttpServer.java

packageorg.jboss.netty.example.http.snoop;

importjava.net.InetSocketAddress;

importjava.util.concurrent.Executors;

importorg.jboss.netty.bootstrap.ServerBootstrap;

importorg.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

publicclassHttpServer {

publicstaticvoidmain(String[] args) {

// Configure the server.

ServerBootstrap bootstrap =newServerBootstrap(

newNioServerSocketChannelFactory(

Executors.newCachedThreadPool(),

Executors.newCachedThreadPool()));

// Set up the event pipeline factory.

bootstrap.setPipelineFactory(newHttpServerPipelineFactory());

// Bind and start to accept incoming connections.

bootstrap.bind(newInetSocketAddress(8081));

}

}

HttpServerPipelineFactory.java

packageorg.jboss.netty.example.http.snoop;

importstaticorg.jboss.netty.channel.Channels.*;

importorg.jboss.netty.channel.ChannelPipeline;

importorg.jboss.netty.channel.ChannelPipelineFactory;

importorg.jboss.netty.handler.codec.http.HttpContentCompressor;

importorg.jboss.netty.handler.codec.http.HttpRequestDecoder;

importorg.jboss.netty.handler.codec.http.HttpResponseEncoder;

publicclassHttpServerPipelineFactoryimplementsChannelPipelineFactory {

publicChannelPipeline getPipeline()throwsException {

// Create a default pipeline implementation.

ChannelPipeline pipeline = pipeline();

// Uncomment the following line if you want HTTPS

//SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();

//engine.setUseClientMode(false);

//pipeline.addLast("ssl", new SslHandler(engine));

pipeline.addLast("decoder",newHttpRequestDecoder());

// Uncomment the following line if you don't want to handle HttpChunks.

//pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));

pipeline.addLast("encoder",newHttpResponseEncoder());

// Remove the following line if you don't want automatic content compression.

pipelin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值