-
最新日志
最新评论
- kauu 发表于《批量修改文件名》
- surfybeach 发表于《批量修改文件名》
- Anonymous 发表于《有感于百度“老人搜索”》
- Anonymous 发表于《感谢上帝,让你做了男人》
- Anonymous 发表于《vim 配置一例》
存档页
- 2012年02月
- 2011年09月
- 2011年04月
- 2011年03月
- 2010年04月
- 2010年03月
- 2010年02月
- 2010年01月
- 2009年12月
- 2009年11月
- 2009年10月
- 2009年09月
- 2009年08月
- 2009年07月
- 2009年04月
- 2009年03月
- 2009年02月
- 2008年12月
- 2008年11月
- 2008年10月
- 2008年07月
- 2008年06月
- 2008年05月
- 2008年04月
- 2008年03月
- 2008年02月
- 2008年01月
- 2007年11月
- 2007年10月
- 2007年09月
- 2007年08月
- 2007年07月
- 2007年06月
- 2007年05月
- 2007年03月
- 2007年02月
- 2007年01月
- 2006年12月
分类
功能
Monthly Archives: 12月 2009
hadoop-core-conf包
在hadoop的map-reduce任务提前时,在mapred中各个要用到的类就已经定好了,所以一般都写成Static类或是方法。已经hadoop会为一个job运用java的反射机制来生成类实例。在job任务指定时,我们并不能从其上下文中取到什么, 或是在各个步骤之间进行普通的同步时编程。 所以问题就出来了。在各个步骤之间怎么传递参数呢? case1: Path filter: 在hdfs里的一个文件夹下, 我们一个task要处理的文件往往都是需要过滤的。而实现PathFilter这个接口的后,可以实现静态的过滤。但是大多数我们的过滤条件是动态的。 怎么解决呢? 一开始我就在想,设计者一定会为此留下一条途径的。在看了代码后,我发现解决这个问题的方法就是用conf包里一个接口Configurable。 为什么它有用呢,让我们来看一段代码: public static PathFilter getInputPathFilter(JobContext context) { Configuration conf = context.getConfiguration(); Class<?> filterClass = conf.getClass("mapred.input.pathFilter.class", null, PathFilter.class); return (filterClass != null) ? … Continue reading
Posted in it技术
Leave a comment
异步log4j日志
平时都是用log4j来作为项目中的日志记录,一般都是用同步的方法来记录。而异步日志对于大并发,或是有网络时则更合适作为日志记录的一种不二选择。 让我们来看一下log4j的异步日志类AsyncAppender。根据这个类的注释,它是自己收集所有的events到一个buffer中,再用一个单独的线程来服务(dispatch)收集过来的events到具体的appender来真正记录日志。(需要注意的是这个类只能通过xml的方法来配置使用) 浏览一下这个类的代码可以看出。它默认用一个大小为128的arraylist来作为event收集的buffer。别起了一个daemon thread来做diaptch event.而这个类里需求注意线程同步问题的地方有buffer,append方法。 在项目中自己写了一个hdfs的appender,用异步来记录是很合适的,而这个类正是我要用到。写好自己的普通appender再用这个类来配置一下,就可以实现异步记录日志了。 <appender name="ASYNC_Test_LOG" class="org.apache.log4j.AsyncAppender"> <param name="BufferSize" value="256"/> <param name="LocationInfo" value="true"/> <appender-ref ref="Test_LOG"/> //Test_LOG是一个普通的appender </appender>
Posted in it技术
Leave a comment