Servlet异步特性在Pushlet推技术中的应用研究

2012-04-29 22:16:26张丽静冼学辉
电脑知识与技术 2012年22期

张丽静 冼学辉

摘要:Pushlet作为一个开源框架,是服务器推技术Comet的一个具体实现。研究了Pushlet推技术,分析Pushlet推技术框架并描述其核心类职责。重点分析Pushlet消息推送机制及其Web容器占用问题。利用Servlet异步特性对Pushlet框架进行优化,给出优化方案,实验证明优化的有效性。

关键词:服务器推送技术;servlet容器;异步处理;性能优化

中图分类号:TP391文献标识码:A文章编号:1009-3044(2012)22-5379-04

Research and Application of Servlet Asynchronous Characteristics in Pushlet Push Technology

ZHANG Li-jing1, XIAN Xue-hui2

(1. Information & Network Management Center, North China Electric Power University, Baoding 071003, China; 2. Department of Computer Science, North China Electric Power University, Baoding 071003, China)

Abstract: As an open source framework, pushlet is a concrete realization of the comet technology. Researched on the pushlet server push technology, analyzed the framework and described the function of core classes. Focused on the analysis of pushlet message pushing mechanism and the threads occupying problem in web container. Optimized pushlet framework by using the asynchronous characteristics of servlet, put forward optimization approaches. Studies show that this solution can effectively improve server performance and highly practical.

Key words: server push technology; servlet container; asynchronous processing; performance optimization

随着Web技术的流行,越来越多的应用从原有C/S模式转变为B/S模式。用户对于数据实时性的需求也越来越多,很多应用例如监控、即时通信、即时报价系统都需要将后台发生的变化实时传送到客户端而无须客户端不停地刷新、发送请求[1]。最近几年,因为AJAX (Asynchronous JavaScript and XML,异步JavaScript和XML)技术的普及,基于纯浏览器的服务器推技术受到较多关注。Comet技术的出现,摆脱了以往采用插件技术(ActiveX、Flash、Applet等)进行Web应用上的推送,解决了跨平台和插件版本兼容性等问题。Comet技术被称为反AJAX(Reverse AJAX)技术,它通过实现服务器推来解决AJAX需要定时频繁发送请求的问题。通过Com? et,客户端所需要的响应信息不再需要主动地去索取,而是在服务器端以事件(Event)的形式推至客户端。

Pushlet是由Just Van Den Broecke设计并编写的一个开源框架,是Comet的一个具体实现。Pushlet在Servlet机制下,将数据从Server端的Java对象直接推送到(动态)HTML页面,无需任何Java Applet或者插件的帮助,它使Server端可以主动、周期性地更新Client端的Web页面[2]。基于Pushlet的主动推送框架构建简单,只需要使用支持Servlet的服务器即可,使用标准HTTP端口进行连接,不会被防火墙拦截[3]。然而,Pushlet存在着可伸缩性问题,其作者也承认问题的存在[4]。……

登录APP查看全文