- 博客(65)
- 收藏
- 关注
转载 Netty的ChannelPipeline学习
Netty的ChannelPipline用了职责链设计模式。我们知道在职责链模式中,每一个hanlder都要设置他的下一个handler的引用,而在netty中,我们只需要直接调用channnelPipeline的add开头的函数,就可以直接把这些handler连接成一条处理线,而客户端只需要编写Channelhandler,而不需在关心他的下一个处理器是什么,这样一是增加了代码的复用...
2016-07-28 17:20:00 182
转载 在Netty上构建Servlet
众所周知,Netty是一款高性能的I/O框架,那怎么在它之上构建Web服务呢,今天网上搜了一篇文章,学习了一下:Java Servletshave been vastly used in companies for more than 10 years now. Recently another project from JBoss namedNettyhas gaine...
2016-07-28 12:36:00 487
转载 网易多线程笔试题目学习
题目:一个线程打印 1~52,另一个线程打印字母A-Z。打印顺序为12A34B56C……5152Z。package my.thread.test; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util...
2016-07-17 22:43:00 187
转载 Nadron的Sping配置文件学习
今天仔细看了下nadron的Spring配置文件,包含了四个文件:收获如下:(1)学习了lookup-method和bean scope这两个常用的标签(2)画了张模型图,梳理下nadron的整体框架小结:1.首先前端的bossgroup用于接收客户的连接,根据端口的不同将数据传入不同的pipeline(Tcp,Udp,Flash)。其中LDGame的js版...
2016-05-06 21:21:00 154
转载 守护线程的学习
这两天在Netty之家看了李老板的一篇文章,主要涉及了NioEventLoop和守护线程,文章最后提出了一个小问题,如下:按照代码运行了一下,并通过java visualVM监控线程运行状态,截图如下:可以发现最终JVM进程在bossGroup中的四个线程全部死掉后自动退出。因为此时的5个用户线程(main线程和nioEventLoopGroup-2中的4个线程)...
2016-05-02 14:31:00 91
转载 Queue和Deque集合的学习
JDK 1.2 就开始有了List和Set以及Map,而Queue接口是从JDK 1.5开始出现stack堆栈,没有迭代器,支持push()方法。后进先出,top()返回最顶端的元素,pop()剔除最顶元素deque双端队列,支持迭代器,有push_back()方法,跟vector差不多,比vector多了个pop_front,push_front方法queue队列,先...
2016-04-28 15:47:00 86
转载 蘑菇街 2017笔试编程题
现有一个n个整数的序列,你要做的就是交换两个数的位置直到整个序列按照升序排列,那么将这个整数序列排好序,需要交换多少次?例如,1,2,3,5,4,我们只需要交换一次,即将5和4交换即可。输入描述:第一行输入一个正整数n(n≤1000),表示数字序列的元素个数,占一行;接下来一行输入从1到n的n个整数排序,中间用空格隔开输出描述:输出序列升序排列需要的最少交换次数...
2016-04-16 20:34:00 178
转载 Patching Array
Given a sorted positive integer arraynumsand an integern, add/patch elements to the array such that any number in range[1, n]inclusive can be formed by the sum of some elements in the arra...
2016-04-12 11:27:00 82
转载 Design patterns in Spring Framework
This article is the 4th about design patterns used in Spring framework. It'll present new 3 patterns implemented in this framework.At the begin, we'll discover 2 patterns belonging to the fam...
2016-03-08 15:12:00 163
转载 从一篇博客中学习InterruptedException
今天找了一篇讲InterruptedException的博客,拿来翻译共同学习一下:Don't swallow InterruptedException. Call Thread.currentThread().interrupt() instead.Have you ever written the following code?try { doSomethi...
2016-02-14 20:45:00 146
转载 InterruptedException的学习
首先贴一下overstack上的一个回答:理解:(1)throws InterruptedException是你方法声明的一部分,也是你调用方法的返回值。(2)当你的方法调用另一个方法的时候抛出了InterruptException异常,你就应该思考:InterruptException对于你的方法来说是不是有意义的结果?如果是,那你的方法就可以进行异常声明并将异常进行向...
2016-02-14 18:21:00 105
转载 Semaphore和CountDownLatch比较
今天上网搜了下闭锁和信号量适用的场合,OverStatckFlow上的一个回答挺好的,如下理解:闭锁适用于启动一系列的线程并等待他们执行完毕(或者是调用了一定次数的countDown函数).信号量是用来控制多个线程共享某个资源.这个资源可以是文件或者是cpu.信号量的数量可以增加也可以减少.原文链接:http://stackoverflow.com/question...
2016-02-12 15:46:00 997
转载 AtomicInteger变量学习
This is an example of how to use theAtomicIntegerclass of Java. Thejava.util.concurrent.atomicpackage provides very useful classes that support lock-free and thread-safe programming on single ...
2016-02-12 10:25:00 151
转载 LinkedHashSet保存元素插入顺序的原理
LinkedHashSet is anextended versionof HashSet. HashSet doesn’t follow any order where as LinkedHashSet maintainsinsertion order. HashSet usesHashMap objectinternally to store it’s elements w...
2016-02-09 19:41:00 1039
转载 HashSet,TreeSet,LinkedHashSet的比较
A Set contains no duplicate elements. That is one of the major reasons to use a set. There are 3 commonly used implementations of Set: HashSet, TreeSet and LinkedHashSet. When and which to use is...
2016-02-09 17:11:00 156
转载 LinkedHashSet的学习
As you already know,LinkedHashSetis an ordered version of HashSet. That means, HashSet doesn’t maintain any order where as LinkedHashSet maintains insertion order of the elements.LinkedH...
2016-02-09 16:50:00 111
转载 TreeSet的学习
TreeSetis another popularimplementation of Set interface along withHashSet andLinkedHashSet. All these implementations of Set interface are requiredin different scenarios. If you don’t want ...
2016-02-09 15:41:00 118
转载 fail-fast实现机制
Arraylist,HashMap,HashSet等容器持有的的fail-fast迭代器,具体实现原理和modcount域有关.Lets looks at following code01 public class FailFastIteratorTest {02 03 public static void main(String[] args) {0...
2016-02-09 10:49:00 95
转载 fail-fast与fail-safe
今天看hashmap源码的时候遇见了fail-fast这个名词,找了一篇博客,学习一下:What is fail safe and fail fast Iterator in Java?Java Collections supports two types of Iterator, fail safe and fail fast. The main distinction ...
2016-02-09 09:21:00 145
转载 HashMap学习之transient
一. 首先贴一篇解释transient关键字的文章What is transient keyword in Java?This article explains about the transient variable and when it will be used in the Java programming. Another important fact is that,...
2016-02-08 14:02:00 453
转载 TreeMap的学习
In this example we will see how and when to usejava.util.TreeMap.ATreeMapis a Map implementation which provides total ordering on its elements. The elements are ordered using their natural or...
2016-02-06 21:44:00 132
转载 Integer的学习
今天看了一篇文章是将Integer的进阶用法的,拿来一块学习下Why YOU should use Integer.valueOf(int)In particular, why you should useInteger.valueOf(int)instead ofnew Integer(int):CACHING.This variant ofval...
2016-02-05 22:33:00 116
转载 从网易的一道多线程笔试题学习wait与notify来控制线程同步
题目:有三个线程分别打印A、B、C,请用多线程编程实现,在屏幕上循环打印10次ABCABC…package my.thread.test;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;public class PrintThreadExa...
2016-02-04 09:14:00 119
转载 When to use CountDownLatch : Java concurrency example tutorial
As per java docs,CountDownLatchis a synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes. CountDownLatch concept is v...
2016-01-31 11:42:00 97
转载 How @ModelAttribute Annotation works in Spring?
In SpringMVC, @ModelAttribute is used at 2 places.1. At Method level2. At Method parameter level.How @ModelAttribute at method level works?package com.customer.controller;import java.sql....
2016-01-29 15:10:00 89
转载 Implement Trie (Prefix Tree) 两种实现方法的比较
class TrieNode { public TrieNode[] children = new TrieNode[26]; public String item = ""; // Initialize your data structure here. public TrieNode() { }...
2016-01-17 10:31:00 60
转载 How to avoid Memory leak issue in Java
What is Memory Leak?Memory leak is a bug that mainly occurs when a program does not release the memory it has obtained for temporary use. In other words we can say it is the conditio...
2016-01-15 19:31:00 118
转载 Notes on the Asynchronous I/O implementation
Fixed Thread PoolAn asynchronous channel group associated with a fixed thread pool of sizeN, submitsNtasks that wait on I/O or completion events from the kernel. Each task simply dequeues an...
2016-01-12 00:03:00 102
转载 Jetserver开源项目学习(八)—— 解码编码器的用法
一.EventEncoder和EventDecoder事件编码器会收到一个事件对象(event object)然后将这个事件对象转换成为ChannelBuffer对象。编码器首先读取事件的类型并作为操作码(缓冲区的第一个字节),然后读取事件体并转换成为ChannelBuffer对象作为信息体。/** * A simple event encoder will receiv...
2016-01-11 17:04:00 143
转载 Jetserver开源项目学习(七)—— ChannelFutureListener的用法
用法一:给通道添加异步接口public void close() { LOG.debug("Going to close tcp connection in class: {}", this .getClass().getName()); Event event = Events.event(nul...
2016-01-11 16:53:00 1132
转载 Java内部类学习(四)—— 接口中的静态内部类
今天在阅读JetServer源码protocal部分的时候碰见了内部类的又一写法。定义一个接口LoginProtocol,包括了一个域和一个方法,然后在其中写了三个内部类,分别实现了该接口,代码如下:package org.menacheri.jetserver.handlers.netty;import static org.menacheri.jetserver.ev...
2016-01-10 16:59:00 348
转载 Jetsever开源项目学习(六)Event学习
这两天看了下nadron和LDGame,梳理了下event事件在nadron中的处理和传播流程。首先,客户端发来的Event对象通过Pipeline传到了LDGameRoom中,然后守护线程Lane将Event对象分派到对应的PlaySession中进行处理,最后将处理好之后结果通过广播通知房间内的其他所有玩家。调试截图如下:通过这...
2016-01-08 22:13:00 121
转载 Java ConcurrentHashMap学习(二)—— ConcurrentHashMap – avoid a common misuse!
If you program systems with Java, you have probably long been using ConcurrentHashMap. This post explores a caveat.ConcurrentHashMap is often introduced to simplify code and application l...
2016-01-07 11:01:00 86
转载 Java ConcurrentHashMap学习 (一)—— HashMap Vs. ConcurrentHashMap Vs. SynchronizedMap – How a HashMap ca...
HashMapis a very powerfuldata structure inJava. We use it everyday and almost in all applications. There are quite a few examples which I have written before onHow to Implement Threadsafe c...
2016-01-07 09:32:00 116
转载 Jetsever开源项目学习(五)Concurrent学习
梳理一下整体的架构,总的来说jetsever采用生产—消费者并行模型,建立在Executor framework上:1.每一个Lane包含一个名字string和线程池(ExecutorService),线程池其实就相当于worker集合2.每一个Lane有一个计数器(AtomicInteger),用来记录进入这个Lane的session的数量,session集合其实就相当于...
2016-01-06 00:38:00 95
转载 Jetsever开源项目学习(四)Session学习
接口Session.javapackage org.menacheri.jetserver.app;import java.util.List;import org.menacheri.jetserver.communication.MessageSender;import org.menacheri.jetserver.communication.M...
2016-01-02 16:08:00 168
转载 Java语法之内部接口的学习 —— What Is Inner Interface in Java?
What is Inner Interface in Java?Inner interface is also called nested interface, which means declare an interface inside of another interface. For example, the Entry interface is declared in...
2016-01-02 07:32:00 290
转载 Jetsever开源项目学习(三)Server学习
首先看一下org.menacheri.jetserver.server包接口Server.javapackage org.menacheri.jetserver.server;import java.net.InetSocketAddress;import org.menacheri.jetserver.app.Session;public int...
2016-01-02 07:00:00 170
转载 Jetsever开源项目学习(一)项目简介
Jetserver is a high speed nio socket based multiplayer java game server written using Netty and Mike Rettig's Jetlang.It is specifically tuned for network based multiplayer games and supports TCP...
2016-01-01 22:15:00 138
转载 Jetsever开源项目学习(二)架构学习—— Jetserver internal details and how it works.
Jet Server - architecture and internal detailsThis section outlines how data flows through jet server, the important classes and interfaces and also which ones need to be extended by users to w...
2016-01-01 08:09:00 195
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人