- 浏览: 670444 次
- 性别:
- 来自: 珠海
文章分类
最新评论
-
qq826928141:
longxing898 写道请教:使用jtds连接sql 20 ...
rapid-framework v3.9新版本发布 -
qq826928141:
美味人间 写道大哥,这个代码生成器怎么无法获取表和列的备注信息 ...
rapid-framework v3.9新版本发布 -
walle1027:
能发一下的测试代码吗?
rabbitmq性能测试 -
在世界的中心呼喚愛:
好东西,我就是参考这个!!!
iBatis3基于方言(Dialect)的分页 -
暂不存在:
怎么将{key}中的值替换掉
rapid系列:发布一款动态构造sql的工具: XsqlBuilder
在一些特殊的场合,我们可能需要使用异步的IO来大幅提高性能.
如日志信息收集.
而rapid-framework提供的异步IO类,使用生产者/消费者的多线程同步模式及Decorator模式,如同使用正常的IO一样,只需套多一层AsyncWriter/AsyncOutputStream,即可将普通IO转换为异步IO来使用.
打开一个异步IO后,将会在后台开启一个异步的线程来写数据.
异步的Writer使用:
BufferedWriter writer = new BufferedWriter(new AsyncWriter(new FileWriter("c:/debug.log"))); writer.write("xxxxx");
异步的OutputStream使用:
BufferedOutputStream output = new BufferedOutputStream(new AsyncOutputStream(new FileOutputStream("c:/debug.log"))); output.write("foo".getBytes());
在output使用完确保output被close,因为在close时,会强制异步线程将数据全部写入最终的targetOutput. 而调用flush()方法则是空操作,不会写数据.
异步IO使用tip(1):
可以将BufferedWriter/BufferedOutputStream的缓冲区加大,以减少写入次数.
异步IO使用tip(2):
在close异步IO时也放在一个单独的线程中,因为在实际应用场景中,close异步IO可能是十分耗时的操作.
AsyncWriter实现源码:
public class AsyncWriter extends Writer { private static Log log = LogFactory.getLog(AsyncWriter.class); private static final int DEFAULT_QUEUE_CAPACITY = 50000; private final static char[] CLOSED_SIGNEL = new char[0]; private Writer out; private DataProcessorThread dataProcessor; private boolean isClosed = false; private BlockingQueue<char[]> queue ; private AsyncExceptinHandler asyncExceptinHandler = new DefaultAsyncExceptinHandler(); private static long threadSeqNumber; private static synchronized long nextThreadID() { return ++threadSeqNumber; } private class DataProcessorThread extends Thread { private boolean enabled = true; private boolean hasRuned = false; DataProcessorThread() { super("AsyncWriter.DataProcessorThread-"+nextThreadID()); setDaemon(true); } public void run() { hasRuned = true; while (this.enabled || !queue.isEmpty()) { char[] buf; try { buf = queue.take(); } catch (InterruptedException e) { // e.printStackTrace(); continue; } if(buf == CLOSED_SIGNEL) { return; } try { out.write(buf); } catch (IOException e) { asyncExceptinHandler.handle(e); } } } } public AsyncWriter(Writer out) { this(out,DEFAULT_QUEUE_CAPACITY,Thread.NORM_PRIORITY + 1); } public AsyncWriter(Writer out,int queueCapacity) { this(out,queueCapacity,Thread.NORM_PRIORITY + 1); } public AsyncWriter(Writer out,int queueCapacity,int dataProcesserThreadPriority) { this(out,new ArrayBlockingQueue(queueCapacity),dataProcesserThreadPriority); } public AsyncWriter(Writer out,BlockingQueue queue,int dataProcesserThreadPriority) { if(out == null) throw new NullPointerException(); if(queue == null) throw new NullPointerException(); this.queue = queue; this.dataProcessor = new DataProcessorThread(); if(dataProcesserThreadPriority != Thread.NORM_PRIORITY) { this.dataProcessor.setPriority(dataProcesserThreadPriority); } this.dataProcessor.start(); this.out = out; } public AsyncWriter(Writer out,AsyncExceptinHandler handler) { this(out); setAsyncExceptinHandler(handler); } public void write(char[] buf, int offset, int length) throws IOException { synchronized (lock) { if(isClosed) throw new IOException("already closed"); try { queue.put(BufferCopyUtils.copyBuffer(buf, offset, length)); } catch (InterruptedException e) { throw new IOException("AsyncWriter occer error",e); } } } public void close() throws IOException { synchronized (lock) { try { isClosed = true; dataProcessor.enabled = false; if(queue.isEmpty()) { queue.offer(CLOSED_SIGNEL); } try { dataProcessor.join(); } catch (InterruptedException e) { //ignore } if(!dataProcessor.hasRuned) { dataProcessor.run(); } }finally { out.close(); } } } public void flush() throws IOException { } protected void finalize() throws Throwable { super.finalize(); if(!isClosed) { log.warn("AsyncWriter not close:"+this); close(); } } public void setAsyncExceptinHandler(AsyncExceptinHandler asyncExceptinHandler) { if(asyncExceptinHandler == null) throw new NullPointerException(); this.asyncExceptinHandler = asyncExceptinHandler; } }
rapid-framework网站:
http://code.google.com/p/rapid-framework
在线javadoc:
http://www.rapid-framework.org.cn/rapid-javadoc-v2.0.x/
发表评论
-
rapid-framework v3.9新版本发布
2010-07-13 21:17 13438hi,all 本次新版本发布最主要的更新内容 ... -
为velocity,freemarker提供jsp:include功能
2010-06-13 19:26 11425一.介绍 使用JSP的都知道jsp:include指令,可以 ... -
rapid-framework发布新版本: v3.5
2010-03-23 19:01 4473本次的主要更新内容是重新拾起flex,重整了flex插件. 而 ... -
扩展freemarker,velocity,实现模板的管道操作
2010-01-12 20:54 4616操作系统中有一个很重要的功能,就是可以使用管道,即将前一个应用 ... -
扩展Velocity,实现模板的继承
2009-12-28 12:00 5503与我之前的扩展freemarker类似,现新增加三个指令:bl ... -
扩展freemarker,实现模板的继承
2009-12-22 10:11 9217现扩展freemarker,新增加三个指令: @ ... -
spring REST中的内容协商(同一资源,多种展现:xml,json,html)
2009-12-21 14:14 21733接上一篇对spring rest的描述. ... -
在jsp中实现"类"的继承关系
2009-12-09 17:59 72391.介绍 使用过python django模板 ... -
rapid-framework发布v3.0 版本
2009-11-11 09:46 4925虽然spring 3.0及ibatis3还未发布,但rap ... -
iBatis3基于方言(Dialect)的分页
2009-10-19 09:29 23779(注:以下代码是基于ibatis3 beta4的扩展,ibat ... -
与Spring BlazeDS Integration相比,更简单的实现来调用spring bean
2009-10-12 11:15 4098注:后面使用SBI替代Spring BlazeDS In ... -
rapid-framework发布v2.5.0版本
2009-09-21 09:54 2264赶在国庆之前发布一个版本,庆祝国庆,:) 更新内 ... -
rapid-validation发布v1.5版本
2008-12-09 11:44 8179在线演示:http://www.rapid-framework ... -
rapid-framework v2.x路线图
2008-09-09 20:43 2680在1.0.2发布以后,很多同学认为切换至struts2 ... -
rapid-framework v1.0.x带控制条的演示视频放出
2008-08-20 13:28 2008很多同学报怨rapid-framework的演示视频太快,现在 ... -
rapid-framework发布v1.0.2版本
2008-08-13 11:39 2663该版本主要增加的相关文档导航,及一些模板及目录的调整 在线文档 ... -
动态构造sql利器:rapid-xsqlbuider 详细说明
2008-08-06 09:07 5019特性列表: 动态构造sql条件语句,提供sql拼接与使用占 ... -
很高兴大家下载rapid-framework
2008-08-04 11:42 7170看到有很多人下载,心情蛮爽的,这个就是做开源最高兴的吧. 大家 ... -
正式发布类似rails的框架:rapid-framework,文档补充中...
2008-07-29 09:11 5113基于spring,struts(struts2),hibe ... -
最适合实际开发需要的:<代码生成器>发布:rapid-generator-v1.0
2008-07-22 09:05 4266现阶段内置模板可以生成的包括: 可以生成java的hibern ...
相关推荐
rapid-framework,hibernate+spring+springMVC 框架整合
rapid-framework-3.9.3.20100923.jar
rapid-framework-v3.0.1.0及源码
资源来自pypi官网。 资源全名:rapid-framework-1.3.0.tar.gz
rapid-framework-common-3.9.3.20100923-src.zip
NULL 博文链接:https://zx527291227.iteye.com/blog/1679332
rapid-framework v3.0.1.0 源码 代码生成工具类
包含: 1.rapid-framework-3.9.2.20100720 2.reference_doc 3.rapid-framework-common-3.9.2.20100720-src
rapid-framework-3.9.3.20100923
rapid-generator是一个生成器引擎,让你可以专注与代码生成器模板的编写, 可以生成如ibatis,ibatis3,hibernate,spring_mvc,struts2等等代码. 该项目是 Rapid Framework 框架的一部分。
SSH框架开发神器,教程很多,工具很到,找到很不容易
rapid-validation样例以及所有CSS和JS
最快速的java代码生成器 rapid-generator
iot-design-rapid-prototyping:鹿特丹教育学院
独立版本 1. 修改generator.xml文件里的数据库配置; 2. 按需修改template文件夹里的内容; 3. 运行rapid-gen.bat
Rapid Framework使用教程,最好的脚手架。板桥的作品。
将 Joomla 启动库下载到服务器后,需要创建两个文件: install.custom.json和update.custom.json ,内容如下: { " require " : { " mikoweb/joomla-rapid-k2-theme " : " dev-master " }} 现在您可以安装 CMS ...
framework rapid 快速开发框架
运行好,调试好的spring3.0 mvc_rest_demo.war ... * Powered By [rapid-framework] * Web Site: http://www.rapid-framework.org.cn * Google Code: http://code.google.com/p/rapid-framework/
NULL 博文链接:https://o0o0o0o.iteye.com/blog/563851