随笔分类 -  JAVA

上一页 1 2 3 4 5 6 ··· 8 下一页
Zero Copy
摘要:原文出处:http://www.ibm.com/developerworks/library/j-zerocopy/传统的I/O使用传统的I/O程序读取文件内容, 并写入到另一个文件(或Socket), 如下程序:File.read(fileDesc, buf, len);Socket.send(s... 阅读全文
posted @ 2014-04-28 01:18 ZimZz 阅读(3619) 评论(1) 推荐(2)
Netty端口被占用问题
摘要:问题:最近发现Netty项目每次发布的时候Netty在重启时都会报端口被占用的异常, 需要过十几秒左右手动重启一遍, Netty才能恢复正常目前猜测是由于Tomcat_restart的时候Netty执行相关的销毁操作, Channel.close().awaitUninterrupted() 以及 ... 阅读全文
posted @ 2014-04-26 22:29 ZimZz 阅读(10236) 评论(0) 推荐(0)
AsyncHttpClient的连接池使用逻辑
摘要:AsyncHttpClient的连接池结构很简单, NettyConnectionsPool内部重要的几个变量如下 // 连接池, 通过 host 区分不同的池 private final ConcurrentHashMap> connectionsPool = new Concurre... 阅读全文
posted @ 2014-04-25 20:51 ZimZz 阅读(6925) 评论(0) 推荐(0)
HashMap 与 ConcurrentHashMap
摘要:1. HashMap1) 并发问题HashMap的并发问题源于多线程访问HashMap时, 如果存在修改Map的结构的操作(增删, 不包括修改), 则有可能会发生并发问题, 表现就是get()操作会进入无限循环 public V get(Object key) { if (key... 阅读全文
posted @ 2014-04-17 21:44 ZimZz 阅读(4048) 评论(0) 推荐(1)
Java NIO Test Case
摘要:package org.zwl.test.nio;import java.io.IOException;import java.net.InetSocketAddress;import java.nio.ByteBuffer;import java.nio.channels.*;import jav... 阅读全文
posted @ 2014-04-15 21:19 ZimZz 阅读(902) 评论(0) 推荐(0)
Netty writeAndFlush() 流程与异步
摘要:Netty writeAndFlush()方法分为两步, 先 write 再 flush @Override public ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) { DefaultCh... 阅读全文
posted @ 2014-04-15 21:15 ZimZz 阅读(54333) 评论(2) 推荐(4)
Java 文件路径相关
摘要:不得不说Java的文件路径弄得很复杂, 有编译目录和resource目录什么的和解释型语言(PHP)的就是不一样搞了好几年java一直没认真去研究这些个破路径怎么回事, 每次都忘记, 梳理一下备忘1. 直接使用绝对路径这是最简单的一种, 例如 new File("/home/alexis/test.... 阅读全文
posted @ 2014-04-13 22:44 ZimZz 阅读(330) 评论(0) 推荐(0)
JMap与JStack
摘要:用JMap和JStack做堆dump和线程dump命令1. jmap -dump:format=b,file=filename pidjmap -dump:format=b,file=jmap0225.bin 18646jmap -histo pid : 查看当期那 heap 的对象sudo -u ... 阅读全文
posted @ 2014-02-25 23:59 ZimZz 阅读(4781) 评论(0) 推荐(0)
Spring的AsyncHandlerInterceptor
摘要:AsyncHandlerInterceptor提供了一个afterConcurrentHandlingStarted()方法, 这个方法会在Controller方法异步执行时开始执行, 而Interceptor的postHandle方法则是需要等到Controller的异步执行完才能执行例如 @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Except... 阅读全文
posted @ 2014-02-19 21:13 ZimZz 阅读(9875) 评论(0) 推荐(0)
Zookeeper Tutorial 1 -- Overview
摘要:ZooKepper: 一个分布式应用的分布式协调服务(Distributed Coordination Service)分布式服务难以管理, 他们容易造成死锁和竞争, ZooKepper的动机就是为了让分布式应用的责任从协调服务中解脱出来.设计目的ZooKeeper很简单ZooKeeper通过共享一个类似于标准文件系统的命名空间(namespace)来协调分布式进程. 命名空间包括数据注册器(data registers) - 用ZooKeeper的语法说, 叫做 znode - 他们类似于文件系统中得文件和目录. 和典型文件系统不一样的是, ZooKeeper设计不是用来做存储的, 它把数据 阅读全文
posted @ 2014-02-18 16:57 ZimZz 阅读(733) 评论(2) 推荐(1)
AsyncHttpClient SSLContext 相关
摘要:111 阅读全文
posted @ 2014-02-12 21:36 ZimZz 阅读(235) 评论(0) 推荐(0)
Spring MVC 返回类型为字符串时, 返回中文变成"?"处理
摘要:Spring controller 如下@Controllerpublic class SimpleController { @ResponseBody @RequestMapping(value = "/hotel") public String hotel() { return "{\"status\":0,\"errmsg\":null,\"data\":{\"query\":\"酒店查询\",\"num\":65544,\"ur 阅读全文
posted @ 2013-12-30 00:17 ZimZz 阅读(11970) 评论(0) 推荐(0)
Netty Associated -- Channel
摘要:A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.一个网络套接字或组件的枢纽, 用来进行 I/O 操作, 例如 read, write, connect, bind.A channel provides a user:一个Channel的提供给用户的东西有:the current state of the channel (e.g. is it open? is it connected?),channel目前的 阅读全文
posted @ 2013-10-20 02:39 ZimZz 阅读(496) 评论(0) 推荐(0)
Netty Associated -- ChannelPipeline
摘要:A list of ChannelHandlers which handles or intercepts inbound events and outbound operations of a Channel. ChannelPipeline implements an advanced form of the Intercepting Filter pattern to give a user full control over how an event is handled and how the ChannelHandlers in a pipeline interact with e 阅读全文
posted @ 2013-10-20 02:17 ZimZz 阅读(1909) 评论(0) 推荐(0)
使用Idea创建多Module工程
摘要:1. 点击 New -- Project2. 设置工程父Pom, 如下 4.0.0 org.test test-parent 1.0.0.Beta com.google.guava guava 15.0 3. 删除父工程Src并创建子Module, 点击 New -- Module4. 将子module的java和resource目录设置为source目录右击java和resource目录, 选择 Mark Directory As -- Source Roo... 阅读全文
posted @ 2013-10-19 21:41 ZimZz 阅读(48250) 评论(1) 推荐(2)
User guide for Netty 4.x
摘要:Table of ContentsPrefaceThe SolutionGetting StartedBefore Getting StartedWriting a Discard ServerLooking into the Received DataWriting an Echo ServerWriting a Time ServerWriting a Time ClientDealing with a Stream-based TransportSpeaking in POJO instead of ByteBufShutting Down Your ApplicationSummary 阅读全文
posted @ 2013-10-18 16:50 ZimZz 阅读(5091) 评论(0) 推荐(0)
Netty Associated -- ByteBuf
摘要:ByteBufByteBuf是Netty的Server与Client之间通信的数据传输载体.他提供了一个byte数组(byte[])的抽象视图buffer创建我们推荐通过一个Unpooled的帮助方法来创建新的buffer而不是通过调用独立的构造器来创建随机访问索引就像普通的原声字节数组一样, By... 阅读全文
posted @ 2013-10-17 20:49 ZimZz 阅读(11973) 评论(1) 推荐(1)
Spring Test, JUnit, Mockito, Hamcrest 集成 Web 测试
摘要:关于Spring 3.21. Spring 3.2 及以上版本自动开启检测URL后缀,设置Response content-type功能, 如果不手动关闭这个功能,当url后缀与accept头不一致时, Response的content-type将会和request的accept不一致,导致报406关闭URL后缀检测的方法如下 2. Spring-Test框架无法应用关闭Spring自动URL后缀检测的设置, 且StandaloneMockMvcBuilder将设置favorPathExtendsion属性的方法设置为protected即 ... 阅读全文
posted @ 2013-10-16 21:30 ZimZz 阅读(11540) 评论(3) 推荐(0)
字符串解析与集合过滤的抽象
摘要:问题如下假设我们有一个类HotelCenter,它有方法List getHotelList(String city)可以获得一个城市下所有酒店列表Hotel类有如下属性String name, String address, int price, Map properties酒店的非name和address的属性都可以通过properties.get(key)得到我们需要实现以下功能根据页面传入的参数返回对应的酒店列表,参数键值对会以&分割,参数的值如果有多个,会有逗号分隔下述任何参数都可能缺失,对应的值如果为空串,也当做该参数不存在处理参数会分三部分组成,过滤参数、排序参数和翻页参数 阅读全文
posted @ 2013-10-16 17:38 ZimZz 阅读(591) 评论(0) 推荐(0)
Unit Testing of Spring MVC Controllers: “Normal” Controllers
摘要:Original link:http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-normal-controllers/Unit Testing of Spring MVC Controllers: “Normal” ControllersbyPETRI KAINULAINENonJULY 7, 2013The first part of this tutorial described how we canconfigure our unit tes 阅读全文
posted @ 2013-10-14 16:56 ZimZz 阅读(2519) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 8 下一页