09 2014 档案
摘要:一、 演示 There are three general strategies for queuing: 排队有三种通用策略: 直接提交。工作队列的默认选项是 SynchronousQueue,它将任务直接提交给线程而不保持它们。在此,如果不存在可用于立即运行任务的线程,则试图把任务加入队列将失败
阅读全文
摘要:一、结构 Lock的实现类其实都是构建在AbstractQueuedSynchronizer上,每个Lock实现类都持有自己内部类Sync的实例 二、LockSupport Basic thread blocking primitives for creating locks and other s
阅读全文
摘要:Servlet Threading ModelThe scalability issues of Java servlets are caused mainly by the server threading model:Thread per connectionThe traditional IO...
阅读全文
摘要:一。thread-per-connectionThe thread-per-connection approach uses an exclusive worker thread foreach connection. Within the handling loop, a worker threa...
阅读全文
摘要:The terms asynchronous and non-blocking are closely related and are often used interchangeably, but they are not quite the same thing. Blocking A func
阅读全文
摘要:一。锁的劣势 (1) 在JDK1.5之前都是使用synchronized关键字保证同步的,这种通过使用一致的锁定协议来协调对共享状态的访问,可以确保无论哪个线程持有守 护变量的锁,都采用独占的方式来访问这些变量 (2)如果出现多个线程同时访问锁,则一些线程将被挂起,当线程恢复执行时,必须等待其它线程
阅读全文
摘要:一。传统数据传输1.user mode &kernel mode2.context switchThe steps involved are:1.The read() call causes a context switch (see Figure 2) from user mode to kern...
阅读全文
摘要:实现FutureTask的要点 1.需要实现一个链表(每个节点包含当前线程的引用) 2.通过LockSupport.park 对线程进行阻塞 3.节点的唤醒(task完成, 线程Interrupt, 或await超时), FutureTask.run 方法 public void run() { /
阅读全文
摘要:一、ThreadLocal的原理以及存在的问题 a. 每个线程内部维护了一个ThreadLocal.ThreadLocalMap类型的变量 b. ThreadLocalMap 的 key 为 ThreadLocal,value为对应的变量 c. 对ThreadLocal进行get/set操作时,会先
阅读全文
摘要:一。server.xml在每个容器对象里面都有一个pipeline,Pipeline就像是每个容器的逻辑总线。 --> --> 二。源码追踪1.Engine /** * Cre...
阅读全文
摘要:一、设计线程安全的类 步骤: 找出构成对象状态的所有变量 找出约束状态变量的不变性条件 建立对象状态的并发访问策略 1.在现有的线程安全类中添加功能 (1)重用能减低工作量和提高正确性 (2)如果底层的类改变了同步策略,使用不同的锁来保护它的状态,则子类会被破坏 2.客户端加锁机制 (1)对于使用对
阅读全文
摘要:一、ThreadLocal 在父子线程传递的问题 二、InheritableThreadLocal 和 ThreadLocal 的区别 1. InheritableThreadLocal 实现 2. ThreadLocal 的getMap、createMap实现 通过上面的代码我们可以看到Inher
阅读全文
摘要:一、示例 线程池内的线程并没有父子关系,所以不适合InheritableThreadLocal的使用场景 二、TransmittableThreadLocal实现分析 读取线程间传递的ThreadLocal 值比较麻烦,ThreadLocal 和 InheritableThreadLocal 都没有
阅读全文
摘要:加锁机制既可以确保可见性又可以确保原子性,而volatile变量只能确保可见性。public class NoVisibility { private static boolean ready; private static int number; private stat...
阅读全文
摘要:Tomcat 经过长时间的发展,它已经广泛的被市场接受和认可,尤其在企业级应用方面,Tomcat 仍然是第一选择。但是随着 Jetty 的发展,Jetty 的市场份额也在不断提高。1.架构 Jetty 比 Tomcat 更加简单。Jetty 的所有组件都是基于 Handler 来实现。可以说 ...
阅读全文
摘要:The Apache JServ Protocol (AJP) is a binary protocol that can proxy inbound requests from a web server through to an application serverthat sits behin...
阅读全文
摘要:Before obtaining an item each thread must acquire a permit from the semaphore, guaranteeing that an item is available for use. When the thread has fin
阅读全文
摘要:转载SPDY 是什么 SPDY 是 Google 开发的基于传输控制协议 (TCP) 的应用层协议 ,开发组正在推动 SPDY 成为正式标准(现为互联网草案)。SPDY 协议旨在通过压缩、多路复用和优先级来缩短网页的加载时间和提高安全性。(SPDY : Speedy )1.SPDY 与 HTTP ...
阅读全文
摘要:Architecture of a Highly Scalable NIO-Based ServerSelectorsA selector (java.nio.channels.Selectorand subclasses) provides a mechanism for waiting on c...
阅读全文