??xml version="1.0" encoding="utf-8" standalone="yes"?>天津体彩11选五走势图:BlogJava - 3d走势图综合版//www.hncyb.com/xylz/关注后端架构、中间件、分布式和并发编?/description>zh-cnMon, 18 Mar 2019 22:18:34 GMTMon, 18 Mar 2019 22:18:34 GMT60世界邦旅行网(北京)招聘Java高级/资深工程师前端工程师/移动开发工程师等_20150616更新 - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/11/05/406019.htmlimxylzimxylzTue, 05 Nov 2013 09:01:00 GMT//www.hncyb.com/xylz/archive/2013/11/05/406019.html//www.hncyb.com/xylz/comments/406019.html//www.hncyb.com/xylz/archive/2013/11/05/406019.html#Feedback15//www.hncyb.com/xylz/comments/commentRss/406019.html//www.hncyb.com/xylz/services/trackbacks/406019.html
  • 工作地点:北?/li>
  • 世界邦旅行网是一个新型出境自助旅行社区和电子商务开放平台,以提供“个性化行程定制服务,高性价比、高质量境外自助游”为目标?/li>
  • 我们的网站://www.shijiebang.com
  • 关于我们?a >//www.shijiebang.com/about/us/
  • B轮数?/li>
  • 招聘职位
    • Java 高级/资深工程?/li>
    • PHP 工程?/li>
    • 测试工程?/li>
    • 前端工程?/li>
    • 移动开发工程师(Android/iOS)
    • 其它市场、推广、运营、产品、设计等人才
  • 待遇
    • 与互联网公司看齐+期权 (价值几何问自己?/li>
  • 特别说明

    • 有github帐号, stackoverflow 有贡献分为佳
    • 不会翻qiang的不建议投递简?/li>
    • 尽管融资有点钱,但依然条件艰苦(创业何其艰)
    • 必须自认为聪明(即使别人认为自己不聪明,要有这份霸气?/li>
    • 对旅游或者旅行有兴趣
    • 一个能够快速自我成长的环境,如果不能建议立即去寻找他处
    • 无意义的技术、工具要求没?/li>
  • 最后的最?/p>

    • 简历写各种精通的,建议不用考虑
  • 联系方式
    • imxylz##gmail.com
  • 更新时间?2015/06/16



    imxylz 2013-11-05 17:01 发表评论
    ]]>
    Java 8 入门/新特?/title><link>//www.hncyb.com/xylz/archive/2013/10/16/405031.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Tue, 15 Oct 2013 16:33:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2013/10/16/405031.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/405031.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2013/10/16/405031.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/405031.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/405031.html</trackback:ping><description><![CDATA[<p>2013/09/05 已经发布?a >JDK 8</a>?a >M8 Developer Preview</a>版本??a >M7(2013/06/13)</a><span class="Apple-converted-space"> </span>所有新特性已经封版, M8 作为开发者预览版,基本上可用,可?a >Oracle网站下载</a>?按照<a >计划</a><a >GA(General Availability)</a>版本 应该?014?月份发布,如果顺利正式版估计和GA版本相同,也就是说在明年3月份就正式使用JDK 8了?/p> <p>这次JDK 8 一共带来了<a >55个新特?/a>,目前所有API应该都已经冻结, 正在进行零bug测试。这次更新的力度比JDK 6/JDK 7都要大,延期了几次,也非常令人期待?我个人准备花费几个月的学习时间,努力跟上Java 8的发布节奏。当然由于对Java 7不太熟悉,因此同时也学习下Java 7的API?/p> <p>目前支持JDK 8的IDE有:</p> <ul class="sqkw"> <li class="sqkw"><a >Netbeans 7.4</a></li> <li class="sqkw"><a >IDEA 12</a></li> <li class="sqkw"><a >非官方的Eclipse</a>, 官方需要到明年Java 8正式发布以后</li> </ul> <p>并非所有JDK 8的特性IDE都能支持,因此需要随时更新IDE以便获得更好的开发环境,推荐使用IDEA?/p> <br /> <h2 class="sqkw">Java 8 新特性入?/h2> <ol> <li class="sqkw">时间?/li> <li class="sqkw">Lambda</li> <li class="sqkw">流式操作 – Stream API</li> <li class="sqkw">接口默认方法 – Default Method</li> <li class="sqkw">日期和时?– Date & Time (JSR 310)</li> <li class="sqkw">集合扩展 – Collections API</li> <li class="sqkw">并发操作 – Concurrency API additions</li> <li class="sqkw">IO/NIO 扩展 – IO/NIO API additions</li> <li class="sqkw">反射和注解更?– Reflection and annotation changes</li> <li class="sqkw">Base64</li> <li class="sqkw">其它各种更新 – Other additions</li> </ol> <hr /> <h2 class="sqkw">Java 7 新特性入?/h2> <ol> <li class="sqkw">字符串在switch中的使用</li> <li class="sqkw">try-with-resources 自动释放资源</li> <li class="sqkw">泛型实例创建的类型推?/li> <li class="sqkw">多异常catch操作</li> <li class="sqkw">文件API扩展</li> <li class="sqkw">集合API更新</li> <li class="sqkw">并发编程API更新</li> <li class="sqkw">Unicode 6.0的支?/li> <li class="sqkw">JDBC 4.1 支持 RowSet 1.1</li> </ol> <p> [更新时间: 2013/10/16] <br/> [原文地址?a target="_blank" >Java 8 入门/新特?/a>] </p><img src ="//www.hncyb.com/xylz/aggbug/405031.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2013-10-16 00:33 <a href="//www.hncyb.com/xylz/archive/2013/10/16/405031.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Bash命令路径的缓?/title><link>//www.hncyb.com/xylz/archive/2013/10/13/path-cache-of-bash-command.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Sun, 13 Oct 2013 14:16:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2013/10/13/path-cache-of-bash-command.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/404935.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2013/10/13/path-cache-of-bash-command.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/404935.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/404935.html</trackback:ping><description><![CDATA[     摘要: Bash 为了提高命令的解析速度,将解析过的命令的全路径保存在hash表中,因此下次执行的时候就无需进行再次解析。如果在shell中修改了已经缓存过的命令路径,那么bash可能不能立即生效。这样就会发生命令不能解析或者文件不存在的问题,尽管可执行文件确实存在?nbsp; <a href='//www.hncyb.com/xylz/archive/2013/10/13/path-cache-of-bash-command.html'>阅读全文</a><img src ="//www.hncyb.com/xylz/aggbug/404935.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2013-10-13 22:16 <a href="//www.hncyb.com/xylz/archive/2013/10/13/path-cache-of-bash-command.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MAC下批量转换PNG和JPEG - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/10/08/404759.htmlimxylzimxylzTue, 08 Oct 2013 09:17:00 GMT//www.hncyb.com/xylz/archive/2013/10/08/404759.html//www.hncyb.com/xylz/comments/404759.html//www.hncyb.com/xylz/archive/2013/10/08/404759.html#Feedback1//www.hncyb.com/xylz/comments/commentRss/404759.html//www.hncyb.com/xylz/services/trackbacks/404759.html sips的名称功能非常强大,参?a target="_blank" >帮助文?br /> 这里我们只用到其中的一个功能,转换图片格式?br />
    命令参考:
        sips -s format jpeg --out b.jpg a.png
    写一个png批量转换jpg的脚本:

        cat  
    ~/bin/png2jpg
        #
    !/bin/bash
        # convert png files to jpeg files
        # usage: png2jpg 
    <file>

        
    for f in "$@"
        
    do
            sips 
    -s format jpeg --out "${f%.*}.jpg" "$f"
        done
    同样写一个jpg批量转换png的脚本:

        cat 
    ~/bin/jpg2png
        #
    !/bin/bash
        # convert jpeg files to png files
        # usage: jpg2png 
    <file>

        
    for f in "$@"
        
    do
            sips 
    -s format png --out "${f%.*}.png" "$f"
        done
    使用例子?br />

        ?nbsp;
    ~/Downloads $ png2jpg QQ20131008-*.png
        
    /Users/adyliu/Downloads/QQ20131008-2.png
          
    /Users/adyliu/Downloads/QQ20131008-2.jpg
        
    /Users/adyliu/Downloads/QQ20131008-3.png
          
    /Users/adyliu/Downloads/QQ20131008-3.jpg
        
    /Users/adyliu/Downloads/QQ20131008-4.png
          
    /Users/adyliu/Downloads/QQ20131008-4.jpg
        ?nbsp;
    ~/Downloads $ ll QQ*
        
    -rw-r--r--  1 adyliu  staff    67K 10  8 15:43 QQ20131008-2.jpg
        
    -rw-r--r--1 adyliu  staff    88K 10  8 15:31 QQ20131008-2.png
        
    -rw-r--r--  1 adyliu  staff    23K 10  8 15:43 QQ20131008-3.jpg
        
    -rw-r--r--1 adyliu  staff    34K 10  8 15:31 QQ20131008-3.png
        
    -rw-r--r--  1 adyliu  staff    47K 10  8 15:43 QQ20131008-4.jpg
        
    -rw-r--r--1 adyliu  staff    44K 10  8 15:31 QQ20131008-4.png

    参考资?
    1. sips doc
    2. Resizing images using the command line
    3. Shell Parameter Expansion
    4. Extract filename and extension in bash
    原文地址?a target="_blank" >//imxylz.com/blog/2013/10/08/batch-convert-png-to-jpeg-on-mac-os/

    imxylz 2013-10-08 17:17 发表评论
    ]]>
    Octopress加速Google字体渲染 - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/09/22/move-google-fonts-to-local-server.htmlimxylzimxylzSun, 22 Sep 2013 13:42:00 GMT//www.hncyb.com/xylz/archive/2013/09/22/move-google-fonts-to-local-server.html//www.hncyb.com/xylz/comments/404298.html//www.hncyb.com/xylz/archive/2013/09/22/move-google-fonts-to-local-server.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/404298.html//www.hncyb.com/xylz/services/trackbacks/404298.html阅读全文

    imxylz 2013-09-22 21:42 发表评论
    ]]>
    JRebel 6.0.0 Crack (20141216更新) - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/09/15/404098.htmlimxylzimxylzSun, 15 Sep 2013 15:24:00 GMT//www.hncyb.com/xylz/archive/2013/09/15/404098.html阅读全文

    imxylz 2013-09-15 23:24 发表评论
    ]]>
    申请SSL证书及Nginx支持HTTPS - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/09/11/403965.htmlimxylzimxylzWed, 11 Sep 2013 13:58:00 GMT//www.hncyb.com/xylz/archive/2013/09/11/403965.html//www.hncyb.com/xylz/comments/403965.html//www.hncyb.com/xylz/archive/2013/09/11/403965.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/403965.html//www.hncyb.com/xylz/services/trackbacks/403965.html阅读全文

    imxylz 2013-09-11 21:58 发表评论
    ]]>
    随机选择集合的子元素集合 - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/08/17/402978.htmlimxylzimxylzSat, 17 Aug 2013 09:44:00 GMT//www.hncyb.com/xylz/archive/2013/08/17/402978.html//www.hncyb.com/xylz/comments/402978.html//www.hncyb.com/xylz/archive/2013/08/17/402978.html#Feedback3//www.hncyb.com/xylz/comments/commentRss/402978.html//www.hncyb.com/xylz/services/trackbacks/402978.html我需要一个从集合N中随机选择M个子元素的算法?当然最好的办法是将集合打乱顺序,然后从中选择前M个元素即可?Java中现成的API可以使用?/div>
    java.util.Collections.shuffle(List<?>)
    此算法非常简单,循环N次,每次长度减少1,随机获取其中一个元素,然后交换其对称元素?/div>
    public static void shuffle(List<?> list, Random rnd) {
        int size = list.size();
        if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
            for (int i=size; i>1; i--)
                swap(list, i-1, rnd.nextInt(i));
        } else {
            Object arr[] = list.toArray();

            // Shuffle array
            for (int i=size; i>1; i--)
                swap(arr, i-1, rnd.nextInt(i));

            // Dump array back into list
            ListIterator it = list.listIterator();
            for (int i=0; i<arr.length; i++) {
                it.next();
                it.set(arr[i]);
            }
        }
    }

    有点意思的swap函数

    public static void swap(List<?> list, int i, int j) {
        final List l = list;
        l.set(i, l.set(j, l.get(i)));
    }

    其实我们的需求很简单,在基本不变的集合中,多次重复随机获取其子集,至于子集是否有序或者随机不重要的, 重要的是原集合中的每个元素都有相似的概率出现在子集合中?/div>

    考虑到性能以及并发访问(多线程)的需要,我想到了一个简单的算法?/div>
    给定N个元素集合,从中选择M(0<M<=N)个元素的办法是,
    1. 随机选择索引K(0<=K<N), i=0, 空子?/li>
    2. 取有效元素N(k-i),N(k+i) 加入未满子集M
    3. i+=1, 重复(2) 直到子集M已满
    4. 终止
    这样取出来的元素虽然和原始集顺序有一定的关系,但是每个元素在子集里出现的概率相当,满足结果要求?最后生成的算法如下?/div>
    public static <T> List<T> randomList(List<T> views, int max) {

        final int size = views.size();
        int index = RandomUtils.nextInt(size);
        //
        List<T> ret = new ArrayList<T>(max);
        int low = index - 1, high = index;
        while (max > 0 && (low >= 0 || high < size)) {
            if (low >= 0 && max-- > 0) {
                ret.add(views.get(low));
            }
            if (high < size && max-- > 0) {
                ret.add(views.get(high));
            }
            low--;
            high++;
        }
        return ret;
    }

    此算法满足如下特点:
    1. 足够?/li>
    2. 线程安全(原始集合不变)
    3. 子元素出现概率相当(未经数学证明

    另外,stackoverflow上也有一些参考链接:



    imxylz 2013-08-17 17:44 发表评论
    ]]>捕获Java线程池执行任务抛出的异常 - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/08/05/402405.htmlimxylzimxylzMon, 05 Aug 2013 08:45:00 GMT//www.hncyb.com/xylz/archive/2013/08/05/402405.html//www.hncyb.com/xylz/comments/402405.html//www.hncyb.com/xylz/archive/2013/08/05/402405.html#Feedback6//www.hncyb.com/xylz/comments/commentRss/402405.html//www.hncyb.com/xylz/services/trackbacks/402405.htmlJava中线程执行的任务接口java.lang.Runnable 要求不抛出Checked异常?/p>
    public interface Runnable {

        
    public abstract void run();
    }

    那么如果 run() 方法中抛出了RuntimeException,将会怎么处理了?

    通常java.lang.Thread对象运行设置一个默认的异常处理方法?/p>

    java.lang.Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler)

    而这个默认的静态全局的异常捕获方法时输出堆栈?/p>

    当然,我们可以覆盖此默认实现,只需要一个自定义的java.lang.Thread.UncaughtExceptionHandler接口实现即可?/p>

    public interface UncaughtExceptionHandler {

        
    void uncaughtException(Thread t, Throwable e);
    }

    而在线程池中却比较特殊。默认情况下,线程池 java.util.concurrent.ThreadPoolExecutor 会Catch住所有异常, 当任务执行完?java.util.concurrent.ExecutorService.submit(Callable))获取其结??java.util.concurrent.Future.get())会抛出此RuntimeException?/t>

    /**
     * Waits if necessary for the computation to complete, and then
     * retrieves its result.
     *
     * 
    @return the computed result
     * 
    @throws CancellationException if the computation was cancelled
     * 
    @throws ExecutionException if the computation threw an exception
     * 
    @throws InterruptedException if the current thread was interrupted while waiting
     
    */
    V get() 
    throws InterruptedException, ExecutionException;

    其中 ExecutionException 异常即是java.lang.Runnable 或?java.util.concurrent.Callable 抛出的异常?/p>

    也就是说,线程池在执行任务时捕获了所有异常,并将此异常加入结果中。这样一来线程池中的所有线程都将无法捕获到抛出的异常?从而无法通过设置线程的默认捕获方法拦截的错误异常?/p>

    也不同通过自定义线?/a>来完成异常的拦截?/p>

    好在java.util.concurrent.ThreadPoolExecutor 预留了一个方法,运行在任务执行完毕进行扩展(当然也预留一个protected方法beforeExecute(Thread t, Runnable r)):

    protected void afterExecute(Runnable r, Throwable t) { } 

    此方法的默认实现为空,这样我们就可以通过继承或者覆盖ThreadPoolExecutor 来达到自定义的错误处理?/p>

    解决办法如下?/p>

    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(111001, TimeUnit.MINUTES, //
            new ArrayBlockingQueue<Runnable>(10000),//
            new DefaultThreadFactory()) {

        
    protected void afterExecute(Runnable r, Throwable t) {
            
    super.afterExecute(r, t);
            printException(r, t);
        }
    };

    private static void printException(Runnable r, Throwable t) {
        
    if (t == null && r instanceof Future<?>) {
            
    try {
                Future
    <?> future = (Future<?>) r;
                
    if (future.isDone())
                    future.get();
            } 
    catch (CancellationException ce) {
                t 
    = ce;
            } 
    catch (ExecutionException ee) {
                t 
    = ee.getCause();
            } 
    catch (InterruptedException ie) {
                Thread.currentThread().interrupt(); 
    // ignore/reset
            }
        }
        
    if (t != null)
            log.error(t.getMessage(), t);
    }

    此办法的关键在于,事实上 afterExecute 并不会总是抛出异常 Throwable t,通过查看源码得知,异常是封装在此时的Future对象中的?而此Future对象其实是一个java.util.concurrent.FutureTask的实现,默认的run方法其实调用?java.util.concurrent.FutureTask.Sync.innerRun()?/v>

    void innerRun() {
        if (!compareAndSetState(0, RUNNING))
            return;
        try {
            runner = Thread.currentThread();
            if (getState() == RUNNING) // recheck after setting thread
                innerSet(callable.call());
            else
                releaseShared(0); // cancel
        } catch (Throwable ex) {
            innerSetException(ex);
        }
    }

    void innerSetException(Throwable t) {
        for (;;) {
            int s = getState();
            if (s == RAN)
                return;
            if (s == CANCELLED) {
                // aggressively release to set runner to null,
                
    // in case we are racing with a cancel request
                
    // that will try to interrupt runner
                releaseShared(0);
                return;
            }
            if (compareAndSetState(s, RAN)) {
                exception = t;
                result = null;
                releaseShared(0);
                done();
                return;
            }
        }
    }

    这里我们可以看到它吃掉了异常,将异常存储在java.util.concurrent.FutureTask.Sync的exception字段中:

    /** The exception to throw from get() */
    private Throwable exception;

    当我们获取异步执行的结果时, java.util.concurrent.FutureTask.get()

    public V get() throws InterruptedException, ExecutionException {
        
    return sync.innerGet();
    }

    java.util.concurrent.FutureTask.Sync.innerGet()

    V innerGet() throws InterruptedException, ExecutionException {
        acquireSharedInterruptibly(
    0);
        
    if (getState() == CANCELLED)
            
    throw new CancellationException();
        
    if (exception != null)
            
    throw new ExecutionException(exception);
        
    return result;
    }

    异常就会被包装成ExecutionException异常抛出?/p>

    也就是说当我们想线程?ThreadPoolExecutor(java.util.concurrent.ExecutorService)提交任务时, 如果不理会任务结果(Feture.get()),那么此异常将被线程池吃掉?/p>

    <T> Future<T> submit(Callable<T> task);
    Future
    <?> submit(Runnable task);

    而java.util.concurrent.ScheduledThreadPoolExecutor是继承ThreadPoolExecutor的,因此情况类似?/p>

    结论,通过覆盖ThreadPoolExecutor.afterExecute 方法,我们才能捕获到任务的异常(RuntimeException)?br />
    原文地址?span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21px;">
    //imxylz.com/blog/2013/08/02/handling-the-uncaught-exception-of-java-thread-pool/



    imxylz 2013-08-05 16:45 发表评论
    ]]>
    Python 基础文件操作 - 3d走势图综合版//www.hncyb.com/xylz/archive/2013/02/24/395677.htmlimxylzimxylzSun, 24 Feb 2013 12:55:00 GMT//www.hncyb.com/xylz/archive/2013/02/24/395677.html//www.hncyb.com/xylz/comments/395677.html//www.hncyb.com/xylz/archive/2013/02/24/395677.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/395677.html//www.hncyb.com/xylz/services/trackbacks/395677.html

    天津体彩11选五走势图:File - 基础文件操作

    学习一门语言,我总是喜欢从文件开始。文本文件的读写操作是我比较在意的基本功能?在这方面,Java语言功能比较强大,用到的设计模式也非常多。只是使用起来太过繁琐?而Python在这方面表现非常好,简洁不失功能,强大不失性能,通俗不失优雅,值得称赞?/p>

    我们从一个最简单的开始?/p>

    with open('/etc/resolv.conf') as f:
    print(f.read())

    这里有用?a style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; color: #751590; -webkit-transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">with语法来关闭文件句柄?/p>

    open()

    首先来了解下open()内置函数?/p>

    open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
    Open file and return a corresponding file object. If the file cannot be opened, an OSError is raised.

    open()的参数众多,通常需要关注的是mode/encoding/errors/newline等?/p>

    最佳实?/h3>
    (1) 读取文件必须传入字符编码encoding 
    (2) 用完的流需要关闭,推荐使用with操作
    (3) 换行符尽可能的使用UNIX格式(\n),尽管python可以智能转换
    (4) 如果可以的话尽可能的使用utf-8编码来处理非ascii字符,不要依赖操作系统的编码

    小贴?/p>

    多个文件同时操作可使用with的语法:

    with open('/etc/hosts','r') as f,open('/tmp/hosts','w') as t:
    //do something

    或?/p>

    with f=open('/etc/hosts'),t=open('/tmp/hosts','w'):
    // do something

    file object

    文件对象描述的是一?#8220;?#8221;操作,通常支持read()或者write()方法?这里的文件对象是一种概念上?#8220;文件对象”,除了常见的真是的磁盘文件,还可以是 标准输入输出文件(stdin/stdout/stderr),内存缓冲区(StringIO,cStringIO)?socket,pipes等?/p>

    这在io模块中有具体的描述?/p>

    文本操作和二进制操作有一些区别。分别介绍?/p>

    Text I/O

    如果mode中包含t(默认),那么返回的流是一个纯文本操作?/p>

    read() 是读取文本的最简单的方法。返回的是字符串形式的结果(和参数encoding有关)?/p>

    read(n)
    Read and return at most n characters from the stream as a single str. If n is negative or None, reads until EOF.

    在很多安装脚本中有:

    readme=open('./README.md').read() 

    类似的用法。这在一个快速结束的程序中问题不大。在正式的服务中应该随时关闭文件句柄释放资源?/p>

    小贴士:

    如果已经读取到文件末尾,read()则返回空字符?'?

    如果要读取一行,使用readline()方法?/p>

    readline(limit=-1)
    Read until newline or EOF and return a single str. If the stream is already at EOF, an empty string is returned. If limit is specified, at most limit characters will be read.

    读取一行意味着和行结束符有关,这个有点复杂?/p>

    读取多行,使用readlines()方法。这将返回一个字符串列表。readlines()也可以限制最多读取多少个字符?/p>

    小贴士:

    readline(limit=-1)和readlines(limit=-1)对limit的描述不太一致?
    readline(limit=-1)描述的是读取一行,最多不超过limit个字符(不是字节),因此有可能结果不是某一行的结束?
    readlines(limit=-1)描述的是读取字符,直到limit个字符所在的行结束。也就是返回的结果一定是某一行的结束(除非EOF)?

    例如?br />>>> open('/tmp/x1','w').write('Python真是一个好同学\n只是限制被割裂成两个版本了\n我支持python3.x')
    40
    >>> open('/tmp/x1','r').readline(10)
    'Python真是一?
    >>> open('/tmp/x1','r').readlines(10)
    ['Python真是一个好同学\n']

    readlines(limit)是一个难以理解的逻辑。如果可以不要随便传输一个参数?a style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; color: #751590; -webkit-transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">参考这?/a>?/p>


    写入文本可使用write(s)方法?/p>

    write(s) Write the string s to the stream and return the number of characters written. 

    写入的是字符串,而不是字节。如果要写入多行字符串,可以使用writelines(lines)方法?/p>

    小贴士:

    write(s)和writelines(lines)不会将行结束符写入文件流。因此需要手动写入行结束符?

    Binary I/O

    二进制流和文本流类似,只是二进制流没有encoding一说。打开二进制流需要传入参数mode中包?#8217;b’?/p>

    例如?/p>

    >>> type(open('/etc/hosts','rb').read())
    <class 'bytes'>

    对比文本流,二进制流有一些小的差别:

    • read()返回的值是字节(bytes)
    • readline()返回的值是字节(bytes),包括换行符
    • readlines()返回的值是字节(bytes)列表,包括换行符
    • write()参数可以?a style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; color: #751590; -webkit-transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">bytes或?a style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; color: #751590; -webkit-transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">bytearray
    • readinto(b)是将内容读取到bytearray b中,返回读取的字节数?/li>

    其它文件操作

    除了read/write方法,文件对象还有一些其它的内置方法?/p>

    • file.close() 关闭文件
    • file.fileno() 获取文件描述符(整形值)
    • file.flush() 对于有缓冲区的写操作,刷新缓冲区
    • file.tell() 返回当前流的字节位置
    • file.seek() 移动文件流的当前位置
    • file.truncate() 截断文件大小

    将在I/O介绍更多的知识?/p>

    imxylz 2013-02-24 20:55 发表评论
    ]]>
    Crack JRebel 5.3.1 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/12/26/393498.htmlimxylzimxylzWed, 26 Dec 2012 04:02:00 GMT//www.hncyb.com/xylz/archive/2012/12/26/393498.html//www.hncyb.com/xylz/comments/393498.html//www.hncyb.com/xylz/archive/2012/12/26/393498.html#Feedback31//www.hncyb.com/xylz/comments/commentRss/393498.html//www.hncyb.com/xylz/services/trackbacks/393498.html
    我一直使?.1.0版本的jrebel,是social免费版本的。social版本会在启动时连接jrebel服务器(myrebel)获取license,同时会将一些热部署的次数、节约时间、性能等日志提交到远程服务器?br /> 最近中国网络抽风,连接jrebel服务器特别慢,导致每次启动的时候都需?0s以上的时间才能得到服务器的响应(加上自动更新检测)。最为一个技术控,很显然,我不能忍受这种行为?br />
    只好研究如何破解它?br /> ?.0开始jrebel的混淆机制做得非常棒,基本上无法进行反编译修改了。好在jrebel比较厚道,一直兼容旧版本的license检测机制,翻出?008年写的破解工程,顺利解决?.1.0版本?br /> 然后下载最新的5.1.2?0121217)版本,尝试了下居然没有成功。太囧了。这是一个小版本,为何改动如此大?br />
    打开debug日志后发现,根本就没有加载jrebel.jar里面的License文件。反编译源码看了下,果然,从5.1.2版本开始不再加载jrebel.jar里面的license文件了,该从用户主目录,jrebel安装目录等获取license文件。这样就没法通过一个jar包分发jrebel了?br /> 将jrebel.lic拷贝到用户主目录?jrebel目录即可?br />
    ~ $ ls ~/.jrebel/jrebel.lic 
    /Users/adyliu/.jrebel/jrebel.lic

    来两张截图?br />
    jrebel 5.1.2 crack
    jrebel 5.1.2 crack

    下载地址


    Updated 2013/03/25
        JRebel更新?.2.0版本,所以可以放出一个低版本(我一直使用)5.1.2?.1.3就暂时不去解决了?br />


    Updated 2013/04/17
        JRebel 更新?.2.2版本,所以可以放出一个低版本5.2.0?br />

    Updated 2013/06/06
        JRebel 更新?.3.0版本,所以可以放出一个低版本5.2.2?br />

    Updated 2013/07/12
        JRebel 更新?.3.1版本,所以可以放出一个低版本5.3.0?br />

    Updated 2013/09/15
        最新版本的下载地址在://www.hncyb.com/xylz/archive/2013/09/15/404098.html

    PS:
         吐槽下,JRebel支持的功能越来越多,导致本身越来越大了,版本5.x已经?M了!!!

     

    关键词: JRebel 5.3.1 crack, JRebel 5.3.0 crack, JRebel 5.2.2 crack, JRebel 5.2.0 crack, JRebel 5.1.2 crack,JRebel 5.1.0 crack, JRebel 5.x crack



    imxylz 2012-12-26 12:02 发表评论
    ]]>
    SQLite3 C语言API入门 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/09/25/388519.htmlimxylzimxylzTue, 25 Sep 2012 08:34:00 GMT//www.hncyb.com/xylz/archive/2012/09/25/388519.html//www.hncyb.com/xylz/comments/388519.html//www.hncyb.com/xylz/archive/2012/09/25/388519.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/388519.html//www.hncyb.com/xylz/services/trackbacks/388519.htmlSQLite3 C语言API入门

    下载SQLite3

    我们下载sqlite源码?/a>,只需要其中的sqlite3.c、sqlite.h即可?/p>

    最简单的一个创建表操作

    #include <stdio.h>
    #include "sqlite3.h"

    int main(int argc,char *argv[]){
        const char *sql_create_table="create table t(id int primary key,msg varchar(128))";
        char *errmsg = 0;
        int ret = 0;

        sqlite3 *db = 0;
        ret = sqlite3_open("./sqlite3-demo.db",&db);
        if(ret != SQLITE_OK){
            fprintf(stderr,"Cannot open db: %s\n",sqlite3_errmsg(db));
            return 1;
        }
        printf("Open database\n");

        ret = sqlite3_exec(db,sql_create_table,NULL,NULL,&errmsg);
        if(ret != SQLITE_OK){
            fprintf(stderr,"create table fail: %s\n",errmsg);
        }
        sqlite3_free(errmsg);
        sqlite3_close(db);

        printf("Close database\n");

        return 0;
    }



    在这个操作中我们执行了如下操作:

    • 打开数据?/li>
    • 执行SQL语句
    • 关闭数据?/li>

    当然这中间会有一些状态的判断以及内存指针的释放等?/p>

    打开数据库的API如下?br />

    int sqlite3_open(
      const char *filename,   /* Database filename (UTF-8) */
      sqlite3 **ppDb          /* OUT: SQLite db handle */
    );
    这里会引入一个非常复杂的sqlite3的数据结构。这个根据需要以后酌情了解些?

     

    打开数据库除了这种形式意外,还有sqlite3_open、sqlite3_open16、sqlite3_open_v2几种形式,基本上类似?/p>

    大部分sql操作都可以通过sqlite3_exec来完成,它的API形式如下?br />

    int sqlite3_exec(
      sqlite3*,                                  /* An open database */
      const char *sql,                           /* SQL to be evaluated */
      int (*callback)(void*,int,char**,char**),  /* Callback function */
      void *,                                    /* 1st argument to callback */
      char **errmsg                              /* Error msg written here */
    );

     

    各个参数的意义为?/p>

    • sqlite3描述的是数据库句?/li>
    • sql 要执行的SQL语句
    • callback回调函数
    • void *回调函数的第一个参?/li>
    • errmsg错误信息,如果没有SQL问题则值为NULL

    回调函数式一个比较复杂的函数。它的原型是这样?

    int callback(void *params,int column_size,char **column_value,char **column_name){

     

    每一个参数意义如下:

    • params是sqlite3_exec传入的第四个参数
    • column_size是结果字段的个数
    • column_value是返回记录的一位字符数组指?/li>
    • column_name是结果字段的名称

    通常情况下callback在select操作中会使用到,尤其是处理每一行记录数。返回的结果每一行记录都会调用下“回调函数”?如果回调函数返回了非0,那么sqlite3_exec将返回SQLITE_ABORT,并且之后的回调函数也不会执行,同时未执行的子查询也不会继续执行?/p>

    对于更新、删除、插入等不需要回调函数的操作,sqlite3_exec的第三、第四个参数可以传入0或者NULL?/p>

    通常情况下sqlite3_exec返回SQLITE_OK=0的结果,?结果可以通过errmsg来获取对应的错误描述?/p>

    Windows下编译:

    D:\home\dev\c>cl /nologo /TC sqlite3-demo.c sqlite3.c 

    GCC下编?

    $ gcc -o sqlite3-demo.bin sqlite3-demo.c sqlite3.c 

    删除表操?/h2>

    为了防止垃圾数据,我们在加载数据库的时候删除表操作?/p>

    简单的删除操作可以直接使用sqlite3_exec即可。这里不需要回调函数以及回调函数的参数?当然需要可以关注sqlite3_exec返回的结果是否为SQLITE_OK的值?br />

        const char *sql_drop_table="drop table if exists t";
        const char *sql_create_table="create table t(id int primary key,msg varchar(128))";

        sqlite3_exec(db,sql_drop_table,0,0,&errmsg);
        sqlite3_exec(db,sql_create_table,0,0,&errmsg);

     

    插入数据

    插入第一条数?br />

        ret = sqlite3_exec(db,"insert into t(id,msg) values(1,'Ady Liu')",NULL,NULL,&errmsg);
        printf("Insert a record %s\n",ret == SQLITE_OK ? "OK":"FAIL");

     

    返回值ret为SQLITE_OK即操作成功?/p>

    插入多条数据,并删除数据

        ret = sqlite3_exec(db,"insert into t(id,msg) values(1,'Ady Liu')",NULL,NULL,&errmsg);
        printf("Insert a record %s\n",ret == SQLITE_OK ? "OK":"FAIL");
        ret = sqlite3_exec(db,"insert into t(id,msg) values(2,'IMXYLZ')",NULL,NULL,&errmsg);
        printf("Insert a record %s\n",ret == SQLITE_OK ? "OK":"FAIL");
        ret = sqlite3_exec(db,"delete from t where id < 3",NULL,NULL,&errmsg);
        printf("Delete records: %s\n",ret == SQLITE_OK ? "OK":"FAIL");
    插入多条数据,简单的使用sqlite3_exec进行SQL执行即可。当然这里是完整的SQL字符串?

     

    预编译操?/h2>
        int i = 0;
        sqlite3_stmt *stmt;
        char ca[255];

        //prepare statement
        sqlite3_prepare_v2(db,"insert into t(id,msg) values(?,?)",-1,&stmt,0);
        for(i=10;i<20;i++){
            sprintf(ca,"HELLO#%i",i);
            sqlite3_bind_int(stmt,1,i);
            sqlite3_bind_text(stmt,2,ca,strlen(ca),NULL);
            sqlite3_step(stmt);
            sqlite3_reset(stmt);
        }
        sqlite3_finalize(stmt);
    预编译操作比较麻烦的,完整的预编译操作的流程是:
    1. 通过sqlite3_prepare_v2()创建一个sqlite3_stmt对象
    2. 通过sqlite3_bind_*()绑定预编译字段的?/li>
    3. 通过sqlite3_step()执行SQL语句
    4. 通过sqlite3_reset()重置预编译语句,重复操作2多次
    5. 通过sqlite3_finalize()销毁资?/li>

    sqlite3_prepare_v2()有个多种类似的形式,完整的API语法是:

    int sqlite3_prepare(
      sqlite3 *db,            /* Database handle */
      const char *zSql,       /* SQL statement, UTF-8 encoded */
      int nByte,              /* Maximum length of zSql in bytes. */
      sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
      const char **pzTail     /* OUT: Pointer to unused portion of zSql */
    );

     

    各个参数的定义为?/p>

    • db为sqlite3的句?/li>
    • zSql为要执行的SQL语句
    • nByte为要执行语句在zSql中的最大长度,如果是负数,那么就需要重新自动计?/li>
    • ppStmt为预编译后的句柄
    • pzTail预编译后剩下的字符串(未预编译成功或者多余的)的指针,通常没什么用,传?或者NULL即可?/li>


    绑定参数sqlite3_bind_*有多种形式,分别对应不同的数据类?

    int sqlite3_bind_blob(sqlite3_stmt*, intconst void*, int n, void(*)(void*));
    int sqlite3_bind_double(sqlite3_stmt*, intdouble);
    int sqlite3_bind_int(sqlite3_stmt*, intint);
    int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
    int sqlite3_bind_null(sqlite3_stmt*, int);
    int sqlite3_bind_text(sqlite3_stmt*, intconst char*, int n, void(*)(void*));
    int sqlite3_bind_text16(sqlite3_stmt*, intconst void*, intvoid(*)(void*));
    int sqlite3_bind_value(sqlite3_stmt*, intconst sqlite3_value*);
    int sqlite3_bind_zeroblob(sqlite3_stmt*, intint n);

     


    预编译SQL语句中可以包含如下几种形式:

    • ?
    • ?NNN
    • :VVV
    • @VVV
    • $VVV

    NNN代表数字,VVV代表字符串?/p>

    如果?或?NNN,那么可以直接sqlite3_bind_*()进行操作,如果是字符串,还需要通过sqlite3_bind_parameter_index()获取对应的index,然后再调用sqlite3_bind_*()操作。这通常用于构造不定条件的SQL语句(动态SQL语句)?/p>

    查询操作

    回调函数的解释参考最上面的描述?首先声明一个回调函数?/p>

    int print_record(void *,int,char **,char **); 


    查询代码

        //select data
        ret = sqlite3_exec(db,"select * from t",print_record,NULL,&errmsg);
        if(ret != SQLITE_OK){
            fprintf(stderr,"query SQL error: %s\n",errmsg);
        }

     

    现在定义回调函数,只是简单的输出字段值?br />

    int print_record(void *params,int n_column,char **column_value,char **column_name){
        int i;
        for(i=0;i<n_column;i++){
            printf("\t%s",column_value[i]);
        }
        printf("\n");
        return 0;
    }

     

    不使用回调的查询操作

    定义使用的变?/p>

     char **dbresult; int j,nrow,ncolumn,index; 

    查询操作

        //select table
        ret = sqlite3_get_table(db,"select * from t",&dbresult,&nrow,&ncolumn,&errmsg);
        if(ret == SQLITE_OK){
            printf("query %i records.\n",nrow);
            index=ncolumn;
            for(i=0;i<nrow;i++){
                printf("[%2i]",i);
                for(j=0;j<ncolumn;j++){
                    printf(" %s",dbresult[index]);
                    index++;
                }
                printf("\n");
            }
        }
        sqlite3_free_table(dbresult);

     

    sqlite3_get_table的API语法?br />

    int sqlite3_get_table(
      sqlite3 *db,          /* An open database */
      const char *zSql,     /* SQL to be evaluated */
      char ***pazResult,    /* Results of the query */
      int *pnRow,           /* Number of result rows written here */
      int *pnColumn,        /* Number of result columns written here */
      char **pzErrmsg       /* Error msg written here */
    );
    void sqlite3_free_table(char **result);

     

    其中?/p>

    • db是sqlite3的句?/li>
    • zSql是要执行的sql语句
    • pazResult是执行查询操作的返回结果?/li>
    • pnRow是记录的行数
    • pnColumn是记录的字段个数
    • pzErrmsg是错误信?/li>

    由于sqlite3_get_table是sqlite3_exec的包装,因此返回的结果和sqlite3_exec类似?/p>

    pazResult是一?pnRow+1)*pnColumn结果集的字符串数组,其中前pnColumn个结果是字段的名称,后pnRow行记录是真实的字段值,如果某个字段为空,则对应值为NULL?/p>

    最后需要通过sqlite3_free_table()释放完整的结果集?/p>

    更新操作

     sqlite3_exec(db,"update t set msg='MESSAGE#10' where id=10",NULL,NULL,&errmsg); 

    当然了,我们也可以使用预编译方法进行更新操作?/p>

    受影响的记录?/h2>

    我们可以使用sqlite3_change(sqlite3 *)的API来统计上一次操作受影响的记录数?/p>

     ret = sqlite3_exec(db,"delete from t",NULL,NULL,&errmsg); 
    if(ret == SQLITE_OK){
    printf("delete records: %i\n",sqlite3_changes(db));
    }

    总结

    这里我们接触了SQLITE3?3个API?/p>

    • sqlite3_open()
    • sqlite3_exec()
    • sqlite3_close()
    • sqlite3_prepare_v2
    • sqlite3_bind_*()
    • sqlite3_bind_parameter_index()
    • sqlite3_step()
    • sqlite3_reset()
    • sqlite3_finalize()
    • sqlite3_get_table
    • sqlite3_change()
    • sqlite3_free()
    • sqlite3_free_table()

    事实上截止到SQLITE3.7.14(2012/09/03) 一共提供了204个API函数?a rel="nofollow" style="text-decoration: none; ">//www.sqlite.org/c3ref/funclist.html)?/a>

    但最精简的API函数大概?个:

    • sqlite3_open()
    • sqlite3_prepare()
    • sqlite3_step()
    • sqlite3_column()
    • sqlite3_finalize()
    • sqlite3_close()

    核心API也就10个(在精简API基础上增?个)?/p>

    • sqlite3_exec()
    • sqlite3_get_table()
    • sqlite3_reset()
    • sqlite3_bind()

    因此掌握起来还是比较容易的?br />
    完整的源码地址?
    https://gist.github.com/3780669



    imxylz 2012-09-25 16:34 发表评论
    ]]>
    分布式消息系统Jafka 发布1.2.0版本 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/06/26/381490.htmlimxylzimxylzTue, 26 Jun 2012 02:51:00 GMT//www.hncyb.com/xylz/archive/2012/06/26/381490.html//www.hncyb.com/xylz/comments/381490.html//www.hncyb.com/xylz/archive/2012/06/26/381490.html#Feedback2//www.hncyb.com/xylz/comments/commentRss/381490.html//www.hncyb.com/xylz/services/trackbacks/381490.htmlJafka 是一个高性能的分布式消息系统。Jafka已经开源,使用github托管,主页地址?/span>https://github.com/adyliu/jafka

    Jafka 发布1.2.0版本?/span>更新记录?/span> 
    • 增加创建Topic的命?nbsp;Issues 4
    • 增加监控Topic消费情况的工?nbsp;Issues 5
    • 添加删除Topic的命?nbsp;Issues 7
    • 忽略IntelliJ IDEA工程文件 Issues 6
    • 支持密码验证某些操作 Issues 8
    • 手动配置broker时支持默认分区数配置 Issues 9
    • 重构发送消息的接口 Issues 10
    • 添加一个默认发送字符串的消息发送?nbsp;Issues 11
    • 添加生成完整完整包的脚本 Issues 12
    • 添加一个导出字符串消息的脚本工?nbsp;Issues 13
    • 修复消费自动分配(负载均衡)失败的问?nbsp;Issues 14
    下载地址?a >https://github.com/adyliu/jafka/downloads
    安装指南?a >https://github.com/adyliu/jafka/wiki/install.zh_CN
    更多文?a >https://github.com/adyliu/jafka/wiki

    imxylz 2012-06-26 10:51 发表评论
    ]]>
    Fedora 17 降级一把辛酸泪 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/06/07/380210.htmlimxylzimxylzThu, 07 Jun 2012 04:13:00 GMT//www.hncyb.com/xylz/archive/2012/06/07/380210.html//www.hncyb.com/xylz/comments/380210.html//www.hncyb.com/xylz/archive/2012/06/07/380210.html#Feedback9//www.hncyb.com/xylz/comments/commentRss/380210.html//www.hncyb.com/xylz/services/trackbacks/380210.html

    Fedora 17发布,第二天立马更新了?首先光是更新就折腾了很久,总算弄好了。结果发现一个巨大的问题。gtk2与eclipse不兼容?/p>

    不兼容的后果是总是报这样的错误(命令行启动eclipse?nbsp;eclipse -debug -consolelog):

    (Eclipse:21798): GLib-GIO-CRITICAL **: g_dbus_proxy_new_for_bus_sync: assertion `g_dbus_is_name (name)' failed

    (Eclipse:21798): GLib-GIO-CRITICAL **: g_dbus_proxy_new_for_bus_sync: assertion `g_dbus_is_name (name)' failed

    (Eclipse:21798): GLib-GIO-CRITICAL **: g_dbus_proxy_new_for_bus_sync: assertion `g_dbus_is_name (name)' failed

    表现为打开编辑器后总是有很多内容无法显示,显示为空白,必须重新选定或者拖动滚动条才能显示?/p>

    这令人崩溃啊!!?/strong>

    这下悲剧了,要知道我的开发工作就是在ecilpse下进行的?/p>

    好吧,上网找找。发现有些人也遇到不兼容问题。但是没有一个解决办法?/p>

    我的解决过程是这样:

    • 更新整个fedora环境(发布后官方发布了一些紧急修正包),未果
    • 重新下载最新发行版的eclipse,未?/li>
    • 重新下载最新的测试版本eclipse,未?/li>
    • 下载fedora18的gtk2、glibc等强制安装,未果
    • 降级gtk2、glibc等到fedora 16,未?/li>
    • 继续google,寻找解决方法,依然未果
    • 替换最新发布的二进制swt库,未果
    • 尝试手动编译swt源码,未成功

    这样,折腾了几天,快要放弃了?/p>

    昨天是在搞不定,尝试下载Idea的社区版,使用了下还是感觉不习惯,放弃?/p>

    今天早上突然想到,公司配的那台笔记本还是Fedora 16未升级。于是想强制降级到swt所有依赖库到Fedora 16看能否解决问题?/p>

    使用了下面命令成功完成了部分依赖库的降级,这里面更是不断的尝试,在失败中成长。哭~~~

    yum list

    yum install

    yum erase

    yum --releasever=16 downgrade

    rpm -qa

    rpm -qf

    ldd

    lsof

    好在只是用了mirrors.sohu.com镜像,绑定了内网地址,下载rpm包非常快。这是是给我最大的安慰?/p>

    这个过程经过了长达两个小时的折腾和仿佛。最终终于成功完成了以下依赖的降级?/p>

    [adyliu@adyliu-pc jafka]$ rpm -qa|grep fc16|sort
    cscope-15.7a-9.fc16.x86_64
    dconf-0.10.0-1.fc16.x86_64
    fcitx-4.2.3-1.fc16.x86_64
    fcitx-data-4.2.3-1.fc16.noarch
    fcitx-gtk2-4.2.3-1.fc16.x86_64
    fcitx-gtk3-4.2.3-1.fc16.x86_64
    fcitx-libs-4.2.3-1.fc16.x86_64
    gdk-pixbuf2-2.24.1-1.fc16.x86_64
    gedit-3.2.6-1.fc16.x86_64
    glib2-2.30.3-1.fc16.x86_64
    glibc-2.14.90-24.fc16.7.x86_64
    glibc-common-2.14.90-24.fc16.7.x86_64
    glibc-devel-2.14.90-24.fc16.7.x86_64
    glibc-headers-2.14.90-24.fc16.7.x86_64
    glib-networking-2.30.1-2.fc16.x86_64
    gnome-disk-utility-libs-3.0.2-3.fc16.x86_64
    gnutls-2.12.14-2.fc16.x86_64
    gsettings-desktop-schemas-3.2.0-1.fc16.noarch
    gtk2-2.24.8-3.fc16.x86_64
    gtk2-immodule-xim-2.24.8-3.fc16.x86_64
    gvfs-1.10.1-3.fc16.x86_64
    libarchive-2.8.5-1.fc16.x86_64
    libbluray-0.2-0.5.20110710git51d7d60a96d06.fc16.x86_64
    libcdio-0.82-6.fc16.x86_64
    libsoup-2.36.1-2.fc16.x86_64
    mdadm-3.2.3-7.fc16.x86_64
    nautilus-3.2.1-2.fc16.x86_64
    nautilus-extensions-3.2.1-2.fc16.x86_64
    PackageKit-0.6.22-2.fc16.x86_64
    PackageKit-glib-0.6.22-2.fc16.x86_64
    PackageKit-gtk-module-0.6.22-2.fc16.x86_64
    PackageKit-yum-0.6.22-2.fc16.x86_64
    pango-1.29.4-1.fc16.x86_64
    yum-3.4.3-24.fc16.noarch

    可以看到仅仅更新gtk2/glibc是不够的?/p>

    总结下:

    • 坚持是成功的关键(中间过程,欲哭无泪,最后我都打算重新安装Fedora 16了)
    • 我还是很强的(囧?br />

    最后警告: 可能会有后遗症,请勿模仿,请勿尝?/strong>?img src ="//www.hncyb.com/xylz/aggbug/380210.html" width = "1" height = "1" />

    imxylz 2012-06-07 12:13 发表评论
    ]]>
    分布式消息系统Jafka 发布1.1.0版本 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/05/27/379308.htmlimxylzimxylzSun, 27 May 2012 02:53:00 GMT//www.hncyb.com/xylz/archive/2012/05/27/379308.html//www.hncyb.com/xylz/comments/379308.html//www.hncyb.com/xylz/archive/2012/05/27/379308.html#Feedback1//www.hncyb.com/xylz/comments/commentRss/379308.html//www.hncyb.com/xylz/services/trackbacks/379308.htmlhttps://github.com/adyliu/jafka

    Jafka 发布1.1.0版本?a target="_blank" >更新记录?br />

    服务?/strong>?/p>

    • 增加 Java Service Wrapper 支持
    • 默认的编?解码调整为字节数?nbsp;2dbc332
    • 增加服务端的mbean ServerInfo,描述版本信息,启动时间、运行时间等
    • 增加getoffset-console.sh脚本,获取broker的偏移量
    • 增加dumper工具,用于导出字符串消息
    • 默认zookeeper 负载均衡重试时间调整?0s
    • 将log4j.properties文件加入服务端CLASSPATH
    • 增加简单安装文?nbsp;INSTALL
    • 默认服务端配置不启用zookeeper
    • 解决一些MBean重复注册问题
    • 大部分IO关闭接口都继承自java.io.Closeable,并提供Closers工具类使?/li>
    • 大量的注释更新以及日志友好化
    • 增加第三方依赖的LICENSE

    客户?/strong>?/p>


    下载地址
    ?

    imxylz 2012-05-27 10:53 发表评论
    ]]>
    ICE Mini Grid - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/05/22/378862.htmlimxylzimxylzTue, 22 May 2012 11:47:00 GMT//www.hncyb.com/xylz/archive/2012/05/22/378862.html//www.hncyb.com/xylz/comments/378862.html//www.hncyb.com/xylz/archive/2012/05/22/378862.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/378862.html//www.hncyb.com/xylz/services/trackbacks/378862.htmlICE Grid 入门?/h3>
    这篇是ICE Grid入门的最简单版?不涉及到IceGride Node)。这里面设计到过多的概念和知识,暂且不表?br />

    创建slice文件

    Printer.ice
     1 // **********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 // **********************************************************************
     8 
     9 module Demo{
    10     interface Printer {
    11         void printString(string s);
    12     };
    13 };

    转换slice

    slice2cpp Printer.ice 

    配置IceGrid Registry
    registry.cfg
    IceGrid.InstanceName=DemoGrid

    Ice.Default.Locator=DemoGrid/Locator:default -p 4061  

    IceGrid.Registry.Client.Endpoints=tcp -p 4061
    IceGrid.Registry.Server.Endpoints=tcp
    IceGrid.Registry.Internal.Endpoints=tcp
    IceGrid.Registry.PermissionsVerifier=DemoGrid/NullPermissionsVerifier
    IceGrid.Registry.AdminPermissionsVerifier=DemoGrid/NullPermissionsVerifier
    IceGrid.Registry.SSLPermissionsVerifier=DemoGrid/NullSSLPermissionsVerifier
    IceGrid.Registry.AdminSSLPermissionsVerifier=DemoGrid/NullSSLPermissionsVerifier
    IceGrid.Registry.Data=./data
    IceGrid.Registry.DynamicRegistration=1

    启动Registry
    icegridregistry --Ice.Config=./registry.cfg &
    启动前最好创建数据目?/data
    mkdir ./data

    服务?/h2> PrinterI.h
     1 //**********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 //**********************************************************************
     8 
     9 #ifndef PRINTER_I_H
    10 #define PRINTER_I_H
    11 
    12 #include <Printer.h>
    13 
    14 using namespace Demo;
    15 using namespace std;
    16 
    17 class PrinterI : public Printer {
    18 public:
    19     virtual void printString(const string& s,const Ice::Current&);
    20 };
    21 
    22 #endif
    23 

    PrinterI.cpp
     1 //**********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 //**********************************************************************
     8 
     9 #include <Ice/Ice.h>
    10 #include <PrinterI.h>
    11 
    12 using namespace std;
    13 
    14 void PrinterI :: printString(const string& s,const Ice::Current&){
    15     cout << s << endl;
    16 }
    17 

    Server.cpp
     1 #include <Ice/Ice.h>
     2 #include <PrinterI.h>
     3 
     4 using namespace std;
     5 
     6 class Server : public Ice::Application {
     7 
     8     public:
     9         virtual int run(int argc,char* argv[]);
    10 };
    11 
    12 int main(int argc,char* argv[]){
    13 
    14     Server app;
    15     int status = app.main(argc,argv,"server.cfg");
    16     return status;
    17 }
    18 
    19 int Server::run(int argc,char* argv[]){
    20     if(argc>1){
    21         cerr<<appName()<<": too many arguments"<<endl;
    22         return EXIT_FAILURE;
    23     }
    24 
    25     Ice::PropertiesPtr properties = communicator()->getProperties();
    26     Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("PrinterAdapter");
    27     Ice::Identity id = communicator()->stringToIdentity("printer");
    28     Demo::PrinterPtr printer = new PrinterI();
    29     adapter->add(printer,id);
    30     adapter->activate();
    31     communicator()->waitForShutdown();
    32     return EXIT_SUCCESS;
    33 }
    34 

    编译
    c++ -I. -I$ICE_HOME/include -c PrinterI.cpp Printer.cpp Server.cpp

    连接
    c++ -o server Printer.o Server.o PrinterI.o -L$ICE_HOME/lib -lIce -lIceUtil -lpthread

    服务端配?br /> server.cfg
    PrinterAdapter.AdapterId=PrinterAdapter
    PrinterAdapter.Endpoints=default
    Ice.Default.Locator=DemoGrid/Locator:tcp -p 4061
    运行服务?br />
    ./server

    客户?/h2> Client.cpp
     1 //**********************************************************************
     2 //
     3 // Copyright (c) 2012 Ady Liu. All rights reserved.
     4 //
     5 // Email: imxylz@gmail.com
     6 //
     7 //**********************************************************************
     8 
     9 #include <Ice/Ice.h>
    10 #include <IceGrid/IceGrid.h>
    11 #include <Printer.h>
    12 
    13 using namespace std;
    14 using namespace Demo;
    15 
    16 int main(int argc,char* argv[]){
    17     int status = 0;
    18     Ice::CommunicatorPtr ic;
    19     PrinterPrx printer;
    20     try{
    21         ic = Ice::initialize(argc,argv);
    22         cout<<"Printer Proxy=>"<<ic->stringToProxy("printer@PrinterAdapter")<<endl;
    23 
    24         try{
    25            printer = PrinterPrx::checkedCast(ic->stringToProxy("printer@PrinterAdapter"));
    26         }catch(const Ice::NotRegisteredException&){
    27             IceGrid::QueryPrx query = IceGrid::QueryPrx::checkedCast(ic->stringToProxy("DemoGrid/Query"));
    28             printer = PrinterPrx::checkedCast(query->findObjectByType("::Demo::Printer"));
    29         }
    30         if(!printer){
    31             cerr<<": could't find a `::Demo::Printer` object."<<endl;
    32             if(ic){
    33                 ic->destroy();
    34             }
    35             return EXIT_FAILURE;
    36         }
    37         printer->printString("Hello world!");
    38     }catch(const Ice::Exception& ex){
    39         cerr << ex << endl;
    40         status = 1;
    41     }catch(const char* msg){
    42         cerr << msg << endl;
    43         status = 2;
    44     }
    45     if(ic){
    46         ic->destroy();
    47     }
    48     return status;
    49 }
    50 

    编译
    c++ -I. -I$ICE_HOME/include -c Printer.cpp Client.cpp

    连接
    c++ -o client Printer.o Client.o -L$ICE_HOME/lib -lIce -lIceUtil -lIceGrid -lGlacier2 -lpthread

    客户端配?br /> client.cfg
    Ice.Default.Locator=DemoGrid/Locator:default -p 4061

    运行客户?br />
    ./client --Ice.Config=./client.cfg


    所有文?/h2>
    grid
    ├── client.cfg
    ├── Client.cpp
    ├── Printer.cpp
    ├── Printer.h
    ├── PrinterI.cpp
    ├── PrinterI.h
    ├── registry.cfg
    ├── server.cfg
    └── Server.cpp


    所有文件下? Ice Mini Guide

    imxylz 2012-05-22 19:47 发表评论
    ]]>分布式消息系统jafka快速起?/title><link>//www.hncyb.com/xylz/archive/2012/05/11/377938.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Fri, 11 May 2012 10:48:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2012/05/11/377938.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/377938.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2012/05/11/377938.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/377938.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/377938.html</trackback:ping><description><![CDATA[     摘要: Jafka 是一个开源的/性能良好的分布式消息系统。在上一篇文章中有所简单介绍?下面是一篇简单的入门文。更多详细的文参考wiki? Step 1: 下载最新的安装?完整的安装指南在这里?最新的发行版地址在:https://github.com/adyliu/jafka/downloads $wget https://github.com/downloads/adyliu/j...  <a href='//www.hncyb.com/xylz/archive/2012/05/11/377938.html'>阅读全文</a><img src ="//www.hncyb.com/xylz/aggbug/377938.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2012-05-11 18:48 <a href="//www.hncyb.com/xylz/archive/2012/05/11/377938.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jafka - 一个高性能的消息系?/title><link>//www.hncyb.com/xylz/archive/2012/05/10/377759.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Thu, 10 May 2012 02:08:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2012/05/10/377759.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/377759.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2012/05/10/377759.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/377759.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/377759.html</trackback:ping><description><![CDATA[<p>Jafka 是一个高性能的分布式消息系统。Jafka已经开源,使用github托管,主页地址?a target="_blank">https://github.com/adyliu/jafka<br /> </a><br /> Jafka 1.0版本已经发布,同步到Maven中央仓库?br /> <br /> Jafka是由Apache孵化的Kafka(由LinkedIn捐助给Apache)克隆而来。Jafka 1.0完整遵循Kafka 0.7的规范,几乎是Kafka的克隆版(有一些改进和调整)?br /> Jafka有几个吸引人的特性:<br /> <br /> <ul class="sqkw"> <li class="sqkw">消息持久化非常快,服务端存储消息的开销为O(1),并且基于文件系统,能够持久化TB级的消息而不损失性能</li> <li class="sqkw">吞吐量很大,在我的单机DELL E6220(现已经停产)、Fedora 16 x86_64下单CPU内核运行,使用Jafka内置的python客户端,吞吐量能够达?00k/s</li> <li class="sqkw">完全的分布式系统,broker、producer、consumer都原生自动支持分布式。自动实现复杂均衡?/li> <li class="sqkw">内核非常小,整个系统(包括服务端和客户端)只有一?72KB的jar包,内部机制也不复杂,适合进行内嵌或者二次开? 。整个服务端加上依赖组件?.5MB?/li> <li class="sqkw">消息格式以及通信机制非常简单,适合进行跨语言开发。目前自带的Python 3.x的客户端支持发送消息和接收消息?/li> </ul> 另外,这里有一个分享的PPT资源?br /> </p> <div style="width: 510px" id="__ss_12795614"><strong style="margin: 12px 0px 4px; display: block"><a title="Jafka guide" target="_blank">Jafka guide</a></strong> <div style="padding-bottom: 12px; padding-left: 0px; padding-right: 0px; padding-top: 5px">View more <a target="_blank">PowerPoint</a> from <a target="_blank">Ady Liu</a> </div> </div> 如果感兴趣,fork在github上的源码,进行二次开发或者按照自己喜欢的方式进行改进。如果有好的特性或者发现bug请友情提醒我?另外,友情支持淘宝内部使用的Kafka克隆?a target="_blank">metaq</a>,内部做了大量的改进和附加组件。如果你需要一个全功能?#8220;复杂”系统,可以试试metaq.<img src ="//www.hncyb.com/xylz/aggbug/377759.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2012-05-10 10:08 <a href="//www.hncyb.com/xylz/archive/2012/05/10/377759.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[深入浅出Jetty 05] Jetty 模块?/title><link>//www.hncyb.com/xylz/archive/2012/04/12/372999.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Thu, 12 Apr 2012 01:39:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2012/04/12/372999.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/372999.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2012/04/12/372999.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/372999.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/372999.html</trackback:ping><description><![CDATA[<!--PageText--> <div id="wikitext"> <h1 class="sqkw"><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> 8.x 模块?/h1> <p><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> 8.x带有一个默认的test环境。我们从这个默认的环境入手? </p> <p class="vspace">首先,来分析下start.ini里面的配置,这个配置决定启动了哪些模块? </p> <div class="vspace"></div><pre class="escaped">$ grep -v "#" start.ini|grep -v "^$" OPTIONS=Server,jsp,jmx,resources,websocket,ext,plus,annotations etc/jetty.xml etc/jetty-annotations.xml etc/jetty-deploy.xml etc/jetty-webapps.xml etc/jetty-contexts.xml etc/jetty-testrealm.xml </pre> <p class="vspace">利用上节学到的只是,我们先来分析下用到了那些模块? </p><pre class="escaped">java -jar start.jar --list-options </pre> <p class="vspace">查找Server,jsp,jmx,resources,websocket,ext,plus,annotations这些对应的模块有? </p><pre class="escaped">GLOBAL option (Appended Entries) (*) ------------------------------------------------------------- 0: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-util-8.1.2.v20120308.jar 1: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-io-8.1.2.v20120308.jar </pre> <pre class="escaped">Option [Server] (Aggregate) ------------------------------------------------------------- 0: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-xml-8.1.2.v20120308.jar 1: 3.0.0.v201112011016 | ${jetty.home}/lib/servlet-api-3.0.jar 2: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-http-8.1.2.v20120308.jar 3: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-continuation-8.1.2.v20120308.jar 4: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-server-8.1.2.v20120308.jar 5: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-security-8.1.2.v20120308.jar 6: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-servlet-8.1.2.v20120308.jar 7: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-webapp-8.1.2.v20120308.jar 8: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-deploy-8.1.2.v20120308.jar 9: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-servlets-8.1.2.v20120308.jar </pre> <pre class="escaped">Option [jsp] ------------------------------------------------------------- 0: 2.2.0.v201108011116 | ${jetty.home}/lib/jsp/com.sun.el-2.2.0.v201108011116.jar 1: 2.2.0.v201108011116 | ${jetty.home}/lib/jsp/javax.el-2.2.0.v201108011116.jar 2: 1.2.0.v201105211821 | ${jetty.home}/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar 3: 2.2.0.v201112011158 | ${jetty.home}/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar 4: 2.2.2.v201112011158 | ${jetty.home}/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar 5: 1.2.0.v201112081803 | ${jetty.home}/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar 6: 3.7.0.M20110909-1335 | ${jetty.home}/lib/jsp/org.eclipse.jdt.core-3.7.1.jar </pre> <pre class="escaped">Option [jmx] ------------------------------------------------------------- 0: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-jmx-8.1.2.v20120308.jar </pre> <pre class="escaped">Option [resources] ------------------------------------------------------------- 0: (dir) | ${jetty.home}/resources </pre> <pre class="escaped">Option [websocket] ------------------------------------------------------------- 0: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-websocket-8.1.2.v20120308.jar </pre> <pre class="escaped">Option [ext] ------------------------------------------------------------- Empty option, no classpath entries active. </pre> <pre class="escaped">Option [plus] ------------------------------------------------------------- 0: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-jndi-8.1.2.v20120308.jar 1: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-plus-8.1.2.v20120308.jar 2: 1.1.0.v201105071233 | ${jetty.home}/lib/jndi/javax.activation-1.1.0.v201105071233.jar 3: 1.4.1.v201005082020 | ${jetty.home}/lib/jndi/javax.mail.glassfish-1.4.1.v201005082020.jar </pre> <pre class="escaped">Option [annotations] ------------------------------------------------------------- 0: 8.1.2.v20120308 | ${jetty.home}/lib/jetty-annotations-8.1.2.v20120308.jar 1: 1.1.0.v201108011116 | ${jetty.home}/lib/annotations/javax.annotation-1.1.0.v201108011116.jar 2: 3.1.0.v200803061910 | ${jetty.home}/lib/annotations/org.objectweb.asm-3.1.0.v200803061910.jar </pre> <p class="vspace">从上一节中我们知道,这些模块相当于将那些组件加入classpath中,jetty在启动时也会装载这些模块? </p><pre class="escaped">$java -jar start.jar --dry-run|awk '{print $4}'|sed 's/:/\n/g' /opt/apps/jetty8/lib/jetty-xml-8.1.2.v20120308.jar /opt/apps/jetty8/lib/servlet-api-3.0.jar /opt/apps/jetty8/lib/jetty-http-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-continuation-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-server-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-security-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-servlet-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-webapp-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-deploy-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-servlets-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-annotations-8.1.2.v20120308.jar /opt/apps/jetty8/lib/annotations/javax.annotation-1.1.0.v201108011116.jar /opt/apps/jetty8/lib/annotations/org.objectweb.asm-3.1.0.v200803061910.jar /opt/apps/jetty8/lib/jetty-jmx-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jsp/com.sun.el-2.2.0.v201108011116.jar /opt/apps/jetty8/lib/jsp/javax.el-2.2.0.v201108011116.jar /opt/apps/jetty8/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar /opt/apps/jetty8/lib/jsp/javax.servlet.jsp-2.2.0.v201112011158.jar /opt/apps/jetty8/lib/jsp/org.apache.jasper.glassfish-2.2.2.v201112011158.jar /opt/apps/jetty8/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar /opt/apps/jetty8/lib/jsp/org.eclipse.jdt.core-3.7.1.jar /opt/apps/jetty8/lib/jetty-jndi-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-plus-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jndi/javax.activation-1.1.0.v201105071233.jar /opt/apps/jetty8/lib/jndi/javax.mail.glassfish-1.4.1.v201005082020.jar /opt/apps/jetty8/resources /opt/apps/jetty8/lib/jetty-websocket-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-util-8.1.2.v20120308.jar /opt/apps/jetty8/lib/jetty-io-8.1.2.v20120308.jar </pre> <p class="vspace">在总结下,不同的OPTION决定了启动不同的模块(也就是不同的组件和classpath)。另外,对于start.config里面的不同的OPTION可能有相同的模块依赖? </p> <p class="vspace">默认的test.war启动了如下模块: </p><ul class="sqkw"><li class="sqkw">Server: 一个标准的servlet容器 </li><li class="sqkw">jsp: jsp模块 </li><li class="sqkw">jmx: jmx支持 </li><li class="sqkw">resources: 允许?{jetty.home}/resources中读取类资源(实际上是配置log4j.properties) </li><li class="sqkw">websocket: 支持websocket的例? </li><li class="sqkw">ext: 由于${jetty.home}/lib/ext目录为空,实际上什么都做。其实此特性是为了装载自定义的组件依赖? </li><li class="sqkw">plus: 一些扩展支持,从上面classpath中猜测,应该是jndi、java认证以及java mail的组件? </li><li class="sqkw">annotations: java注解以及字节码的支持? </li></ul><div class="vspace"></div><h2 class="sqkw">test.war配置</h2> <p>再来看看加载jetty配置? test.war模块默认加载?个配置组件? </p><pre class="escaped">etc/jetty.xml etc/jetty-annotations.xml etc/jetty-deploy.xml etc/jetty-webapps.xml etc/jetty-contexts.xml etc/jetty-testrealm.xml </pre> <div class="vspace"></div><h3><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.xml</h3> <p>默认的jetty.xml负责配置设置服务器的参数,包括绑定的地址、线程池大小以及一些默认的处理?Handler)等? </p><pre class="escaped"><Configure id="Server" class="org.eclipse.jetty.server.Server"> <Set name="ThreadPool"> <New class="org.eclipse.jetty.util.thread.QueuedThreadPool"> <Set name="minThreads">10</Set> <Set name="maxThreads">200</Set> <Set name="detailedDump">false</Set> </New> </Set> <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.server.nio.SelectChannelConnector"> <Set name="host"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.host" /></Set> <Set name="port"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.port" default="8080"/></Set> <Set name="maxIdleTime">300000</Set> <Set name="Acceptors">2</Set> <Set name="statsOn">false</Set> <Set name="confidentialPort">8443</Set> <Set name="lowResourcesConnections">20000</Set> <Set name="lowResourcesMaxIdleTime">5000</Set> </New> </Arg> </Call> <Set name="handler"> <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <Item> <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/> </Item> <Item> <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/> </Item> </Array> </Set> </New> </Set> <Set name="stopAtShutdown">true</Set> <Set name="sendServerVersion">true</Set> <Set name="sendDateHeader">true</Set> <Set name="gracefulShutdown">1000</Set> <Set name="dumpAfterStart">false</Set> <Set name="dumpBeforeStop">false</Set> </Configure> </pre> <p class="vspace">可以看出默认的线程池大小是最小线?0个,最大线?00个。绑定在所有网卡的8080端口。其它配置以后再分析? </p> <div class="vspace"></div><h3><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-annotation.xml</h3> <p><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-annotation.xml配置应该是描述支持哪些注解配置方式? </p><pre class="escaped"> <Call name="setAttribute"> <Arg>org.eclipse.jetty.webapp.configuration</Arg> <Arg> <Array type="java.lang.String"> <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item> <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item> <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item> <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item> <Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item> <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item> </Array> </Arg> </Call> </pre> <div class="vspace"></div><h3><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-deploy.xml</h3> <p><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-deploy.xml配置web发布方式? </p><pre class="escaped"> <Call name="addBean"> <Arg> <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager"> <Set name="contexts"> <Ref id="Contexts" /> </Set> <Call name="setContextAttribute"> <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg> <Arg>.*/servlet-api-[^/]*\.jar$</Arg> </Call> </New> </Arg> </Call> </pre> <p>事实上这里没有定义要发布的目录或者应用位置,因此jetty-deploy依赖于jetty-contexts.xml或者jetty-webapps.xml? </p> <div class="vspace"></div><h3><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-webapps.xml</h3> <p><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-webapps.xml定义要发布的内容,通常是要发布应用或者应用的定义。默认是存放?{jetty.home}/webapps下的应用以及${jetty.home}/contexts下的xml定义? </p><pre class="escaped"> <Ref id="DeploymentManager"> <Call id="webappprovider" name="addAppProvider"> <Arg> <New class="org.eclipse.jetty.deploy.providers.WebAppProvider"> <Set name="monitoredDirName"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="." />/webapps</Set> <Set name="defaultsDescriptor"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="."/>/etc/webdefault.xml</Set> <Set name="scanInterval">1</Set> <Set name="contextXmlDir"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="." />/contexts</Set> <Set name="extractWars">true</Set> </New> </Arg> </Call> </Ref> </pre> <div class="vspace"></div><h3><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-contexts.xml</h3> <p><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-contexts.xml定义一些预置规则。类似于一些拦截器。例如可以讲某些URI rewrite或者静态资源cache配置等? </p> <p class="vspace">这会自动扫描${jetty.home}/contexts下面的xml配置? </p><pre class="escaped"> <Ref id="DeploymentManager"> <Call name="addAppProvider"> <Arg> <New class="org.eclipse.jetty.deploy.providers.ContextProvider"> <Set name="monitoredDirName"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="." />/contexts</Set> <Set name="scanInterval">1</Set> </New> </Arg> </Call> </Ref> </pre> <div class="vspace"></div><h3><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-testrealm.xml</h3> <p><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-testrealm.xml用于test.war的特定配置,用于配置一些认证信息? </p><pre class="escaped"> <Call name="addBean"> <Arg> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">Test Realm</Set> <Set name="config"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="."/>/etc/realm.properties</Set> <Set name="refreshInterval">0</Set> </New> </Arg> </Call> </pre> <div class="vspace"></div><h2 class="sqkw">test.xml</h2> <p>事实上这么模块的配置都是?lt;Configure id="Server" class="org.eclipse.jetty.server.Server">节点配置下? 因此可以合并成一个大的xml。这样做的好处是在一个xml包含所有配置,方便灵活定义。当然,坏处就是复用率低? </p><pre class="escaped"><?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "//www.eclipse.org/jetty/configure.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <Set name="ThreadPool"> <!-- Default queued blocking threadpool --> <New class="org.eclipse.jetty.util.thread.QueuedThreadPool"> <Set name="minThreads">10</Set> <Set name="maxThreads">200</Set> <Set name="detailedDump">false</Set> </New> </Set> <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.server.nio.SelectChannelConnector"> <Set name="host"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.host" /></Set> <Set name="port"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.port" default="8080"/></Set> <Set name="maxIdleTime">300000</Set> <Set name="Acceptors">2</Set> <Set name="statsOn">false</Set> <Set name="confidentialPort">8443</Set> <Set name="lowResourcesConnections">20000</Set> <Set name="lowResourcesMaxIdleTime">5000</Set> </New> </Arg> </Call> <Set name="handler"> <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <Item> <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/> </Item> <Item> <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/> </Item> </Array> </Set> </New> </Set> <Set name="stopAtShutdown">true</Set> <Set name="sendServerVersion">true</Set> <Set name="sendDateHeader">true</Set> <Set name="gracefulShutdown">1000</Set> <Set name="dumpAfterStart">false</Set> <Set name="dumpBeforeStop">false</Set> <Call name="setAttribute"> <Arg>org.eclipse.jetty.webapp.configuration</Arg> <Arg> <Array type="java.lang.String"> <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item> <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item> <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item> <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item> <Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item> <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item> </Array> </Arg> </Call> <Call name="addBean"> <Arg> <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager"> <Set name="contexts"> <Ref id="Contexts" /> </Set> <Call name="setContextAttribute"> <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg> <Arg>.*/servlet-api-[^/]*\.jar$</Arg> </Call> </New> </Arg> </Call> <Ref id="DeploymentManager"> <Call id="webappprovider" name="addAppProvider"> <Arg> <New class="org.eclipse.jetty.deploy.providers.WebAppProvider"> <Set name="monitoredDirName"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="." />/webapps</Set> <Set name="defaultsDescriptor"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="."/>/etc/webdefault.xml</Set> <Set name="scanInterval">1</Set> <Set name="contextXmlDir"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="." />/contexts</Set> <Set name="extractWars">true</Set> </New> </Arg> </Call> </Ref> <Ref id="DeploymentManager"> <Call name="addAppProvider"> <Arg> <New class="org.eclipse.jetty.deploy.providers.ContextProvider"> <Set name="monitoredDirName"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="." />/contexts</Set> <Set name="scanInterval">1</Set> </New> </Arg> </Call> </Ref> <Call name="addBean"> <Arg> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">Test Realm</Set> <Set name="config"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.home" default="."/>/etc/realm.properties</Set> <Set name="refreshInterval">0</Set> </New> </Arg> </Call> </Configure> </pre> <p class="vspace">我们将test.xml放入etc目录下面。这是保持start.ini文件不存在,也就是不使用start.ini里面的配置? </p> <p class="vspace">手动运行它? </p><pre class="escaped">java -jar start.jar OPTIONS=Server,jsp,jmx,resources,websocket,ext,plus,annotations etc/test.xml </pre> <p class="vspace">这时候的启动就和默认启动是一样的了? </p> <p class="vspace">这时候就可以访问了? </p> <div class="vspace"></div><h2 class="sqkw"><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> Statistics</h2> <p>这一部分,我们利用学习到的只是来部署一个Jetty统计模块? </p> <div class="vspace"></div><h3>修改设置</h3> <p>将连接计数参数打开? </p><pre class="escaped"> <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.server.nio.SelectChannelConnector"> <Set name="host"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.host" /></Set> <Set name="port"><Property name="<a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.port" default="8080"/></Set> <Set name="maxIdleTime">300000</Set> <Set name="Acceptors">2</Set> <Set name="statsOn">true</Set><!-- modify this --> </New> </Arg> </Call> </pre> <div class="vspace"></div><h3>设置servlet</h3> <p>为了不影响默认的test.war环境,我们增加一个最简单的WAR环境? </p> <p class="vspace">根据前面学到的知识,只需要将war环境放到webapps目录下即可。可以是一个war包,也可以是一个以.war结尾的目录? </p><pre class="escaped">$tree webapps/demo.war/ webapps/demo.war/ `-- WEB-INF |-- <a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-web.xml `-- web.xml 1 directory, 2 files </pre> <div class="vspace"></div><pre class="escaped">$cat webapps/demo.war/WEB-INF/jetty-web.xml </pre> <pre class="escaped"><?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "//www.eclipse.org/jetty/configure.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/demo</Set> </Configure> </pre> <div class="vspace"></div><pre class="escaped">$cat webapps/demo.war/WEB-INF/web.xml </pre> <pre class="escaped"><?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="//java.sun.com/xml/ns/javaee" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="//java.sun.com/xml/ns/javaee //java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="false" version="3.0"> <display-name>static demo</display-name> <servlet> <servlet-name>statistic</servlet-name> <servlet-class>org.eclipse.jetty.servlet.StatisticsServlet</servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>restrictToLocalhost</param-name><param-value>false</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>statistic</servlet-name> <url-pattern>/statistic/*</url-pattern> </servlet-mapping> </web-app> </pre> <p class="vspace">说明几点? </p><ul class="sqkw"><li class="sqkw">为了不和test.war的contextPath混淆,这里强制修改为/demo? </li><li class="sqkw">增加一个jetty内置的统计servlet(org.eclipse.jetty.servlet.StatisticsServlet) </li><li class="sqkw">将servlet的参数restrictToLocalhost修改为false,否则默认情况下只能通过本机访问,不能远程访? </li></ul><div class="vspace"></div><h3>运行demo</h3> <p>保持test.war不变增加一个统计配置? </p><pre class="escaped">$java -jar start.jar etc/jetty-stats.xml </pre> <div class="vspace"></div><h3>执行效果</h3> <p>使用浏览器访? </p><pre class="escaped">//127.0.0.1:8080/demo/statistic/ </pre> <p class="vspace">效果如下? </p><div class="sqkw"><img src="//dev.imxylz.info/wiki/./wiki/upload/Jetty/statistic1.png" alt="" title="" /></div> <div class="sqkw"><img src="//dev.imxylz.info/wiki/./wiki/upload/Jetty/statistic2.png" alt="" title="" /></div> <p class="vspace">统计结果包含6个部分: </p><ol><li class="sqkw">统计结果收集时间 </li><li class="sqkw">请求数详情(当前请求数、最大请求数、总共请求数、请求时间等? </li><li class="sqkw">请求分发详情(和请求数不同的是,这是jetty内部分发请求的数量,包括forward/include等) </li><li class="sqkw">响应状态详情(1xx/2xx/3xx/4xx/5xx以及总共发送的字节数) </li><li class="sqkw">连接数详?(当前连接数、最大连接数、连接持续时间等? </li><li class="sqkw">内存状况(堆内存和非堆内存使用状?非堆内存通常也称永久代内存) </li></ol><div class="vspace"></div><h2 class="sqkw">小结</h2> <p><a title="" href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> 8.x已经将各个模块拆分非常详细了。每一个模块的命名都非常有规律。通常从名称上就能够猜测出模块的作用? </p> <p class="vspace">部分模块可能还需要对应的配置?{jetty.home}/etc下面有大量的配置,这些零散的配置拆分是为了可复用? 如果一个jetty要想启动多个java进程,那么只需要指定不同的配置即可。甚至为了方便定制化,可能为每一个java进程创建一个完整的jetty.xml配置,而不需?{jetty.home}/etc下面的配置? </p> </div><img src ="//www.hncyb.com/xylz/aggbug/372999.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2012-04-12 09:39 <a href="//www.hncyb.com/xylz/archive/2012/04/12/372999.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[深入浅出Jetty] 文章索引 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/04/12/371612.htmlimxylzimxylzThu, 12 Apr 2012 01:38:00 GMT//www.hncyb.com/xylz/archive/2012/04/12/371612.html//www.hncyb.com/xylz/comments/371612.html//www.hncyb.com/xylz/archive/2012/04/12/371612.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/371612.html//www.hncyb.com/xylz/services/trackbacks/371612.html
    1. [深入浅出Jetty 01] Jetty 8.x 安装
    2. [深入浅出Jetty 02] Jetty 8.x 简单试?/a>
    3. [深入浅出Jetty 03] 简单的RESTful入门
    4. [深入浅出Jetty 04] Jetty的启动方?/a>
    5. [深入浅出Jetty 05] Jetty 模块?/a>


    imxylz 2012-04-12 09:38 发表评论
    ]]>
    [深入浅出Jetty 04]Jetty的启动方?/title><link>//www.hncyb.com/xylz/archive/2012/03/28/372923.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Wed, 28 Mar 2012 11:02:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2012/03/28/372923.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/372923.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2012/03/28/372923.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/372923.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/372923.html</trackback:ping><description><![CDATA[Jetty提供了众多的参数和配置来保证满足不同场景下的启动方式?br /> <br /> 除了极大方便嵌入式启动之外,从程序外部也非常好容易启动jetty?br /><br />[原文://www.hncyb.com/xylz/archive/2012/03/28/372923.html]<br /> <h2 class="sqkw">运行方式</h2> <h3>运行方法1</h3> 首先我们以一个标准的jar程序启动来看待这个问? <br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->[adyliu<span style="color: #800080; ">@adyliu</span>-pc jetty8]<span style="color: #008000; ">$</span><span style="color: #008000; "> cat run.sh <br /> #!/bin/bash</span><span style="color: #008000; "><br /> </span><br /> JETTY_CLASSPATH=<span style="font-weight: bold; ">"</span><span style="font-weight: bold; ">./start.jar</span><span style="font-weight: bold; ">"</span><br /> <span style="color: #0000FF; ">for</span> f in `find ./lib -name <span style="font-weight: bold; ">"</span><span style="font-weight: bold; ">*.jar</span><span style="font-weight: bold; ">"</span>`<br /> <span style="color: #0000FF; ">do</span><br />     JETTY_CLASSPATH=<span style="color: #800080; ">$JETTY_CLASSPATH</span>:<span style="color: #800080; ">$f</span><br /> done<br /> <br /> <span style="color: #008000; ">#</span><span style="color: #008000; ">echo $JETTY_CLASSPATH</span><span style="color: #008000; "><br /> </span>java -cp <span style="color: #800080; ">$JETTY_CLASSPATH</span> $*</div> <br /> <div class="sqkw">然后运行查看?/div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->[adyliu<span style="color: #800080; ">@adyliu</span>-pc jetty8]<span style="color: #008000; ">$</span><span style="color: #008000; "> sh run.sh org.eclipse.jetty.start.Main</span><span style="color: #008000; "><br /> </span><span style="color: #800000; ">2012</span>-<span style="color: #800000; ">03</span>-<span style="color: #800000; ">28</span> <span style="color: #800000; ">16</span>:<span style="color: #800000; ">00</span>:<span style="color: #800000; ">57.532</span>:INFO:oejs.Server:jetty-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308<br /> <span style="color: #800000; ">2012</span>-<span style="color: #800000; ">03</span>-<span style="color: #800000; ">28</span> <span style="color: #800000; ">16</span>:<span style="color: #800000; ">00</span>:<span style="color: #800000; ">57.578</span>:INFO:oejs.AbstractConnector:Started SelectChannelConnector@<span style="color: #800000; ">0.0</span>.<span style="color: #800000; ">0.0</span>:<span style="color: #800000; ">8080</span></div> <div class="sqkw"><br /> 由于没有任何web环境,因此此时访问任何地址应该都是404。测试一下:</div> <div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->[adyliu<span style="color: #800080; ">@adyliu</span>-pc jetty8]<span style="color: #008000; ">$</span><span style="color: #008000; "> curl -v //127.0.0.1:8080</span><span style="color: #008000; "><br /> </span>* About to <span style="color: #0000FF; ">connect</span>() to <span style="color: #800000; ">127.0</span>.<span style="color: #800000; ">0.1</span> port <span style="color: #800000; ">8080</span><br /> *   Trying <span style="color: #800000; ">127.0</span>.<span style="color: #800000; ">0.1</span><img src="//www.hncyb.com/Images/dot.gif" alt="" /> connected<br /> * Connected to <span style="color: #800000; ">127.0</span>.<span style="color: #800000; ">0.1</span> (<span style="color: #800000; ">127.0</span>.<span style="color: #800000; ">0.1</span>) port <span style="color: #800000; ">8080</span><br /> > GET / HTTP/<span style="color: #800000; ">1.1</span><br /> > User-Agent: curl/<span style="color: #800000; ">7.15</span>.<span style="color: #800000; ">5</span> (x86_64-redhat-linux-gnu) libcurl/<span style="color: #800000; ">7.15</span>.<span style="color: #800000; ">5</span> OpenSSL/<span style="color: #800000; ">0.9</span>.8b zlib/<span style="color: #800000; ">1.2</span>.<span style="color: #800000; ">3</span> libidn/<span style="color: #800000; ">0.6</span>.<span style="color: #800000; ">5</span><br /> > Host: <span style="color: #800000; ">127.0</span>.<span style="color: #800000; ">0.1</span>:<span style="color: #800000; ">8080</span><br /> > <span style="color: #0000FF; ">Accept</span>: */*<br /> > <br /> < HTTP/<span style="color: #800000; ">1.1</span> <span style="color: #800000; ">404</span> Not Found<br /> < Date: Wed, <span style="color: #800000; ">28</span> Mar <span style="color: #800000; ">2012</span> <span style="color: #800000; ">08</span>:<span style="color: #800000; ">15</span>:<span style="color: #800000; ">27</span> GMT<br /> < Content-Type: text/html<br /> < Content-<span style="color: #0000FF; ">Length</span>: <span style="color: #800000; ">618</span><br /> < Server: Jetty(<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308)<br /> <HTML><br /> <HEAD><br /> <TITLE>Error <span style="color: #800000; ">404</span> - Not Found</TITLE><br /> <BODY><br /> <H2>Error <span style="color: #800000; ">404</span> - Not Found.</H2></div> <h3>运行方法2</h3> <div class="sqkw">另外上述运行等价于:</div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->[adyliu<span style="color: #800080; ">@adyliu</span>-pc jetty8]<span style="color: #008000; ">$</span><span style="color: #008000; "> sh run.sh org.eclipse.jetty.xml.XmlConfiguration etc/jetty.xml</span><span style="color: #008000; "><br /> </span><span style="color: #800000; ">2012</span>-<span style="color: #800000; ">03</span>-<span style="color: #800000; ">28</span> <span style="color: #800000; ">16</span>:<span style="color: #800000; ">31</span>:<span style="color: #800000; ">16.481</span>:INFO:oejs.Server:jetty-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308<br /> <span style="color: #800000; ">2012</span>-<span style="color: #800000; ">03</span>-<span style="color: #800000; ">28</span> <span style="color: #800000; ">16</span>:<span style="color: #800000; ">31</span>:<span style="color: #800000; ">16.518</span>:INFO:oejs.AbstractConnector:Started SelectChannelConnector@<span style="color: #800000; ">0.0</span>.<span style="color: #800000; ">0.0</span>:<span style="color: #800000; ">8080</span></div> <h3>运行方法3</h3> <div class="sqkw">第三种方法就是使用封装好的start.jar,这个jar包封装了一些常规的配置?/div> <div class="sqkw"><br /> 在开始之前,我们先重命名下默认的start.ini,因为默认的配置文件会启动一个test.war环境?/div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->mv start.ini start.ini.default</div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->[adyliu<span style="color: #800080; ">@adyliu</span>-pc jetty8]<span style="color: #008000; ">$</span><span style="color: #008000; "> java -jar start.jar</span><span style="color: #008000; "><br /> </span><span style="color: #800000; ">2012</span>-<span style="color: #800000; ">03</span>-<span style="color: #800000; ">28</span> <span style="color: #800000; ">16</span>:<span style="color: #800000; ">35</span>:<span style="color: #800000; ">21.941</span>:INFO:oejs.Server:jetty-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308<br /> <span style="color: #800000; ">2012</span>-<span style="color: #800000; ">03</span>-<span style="color: #800000; ">28</span> <span style="color: #800000; ">16</span>:<span style="color: #800000; ">35</span>:<span style="color: #800000; ">21.992</span>:INFO:oejs.AbstractConnector:Started SelectChannelConnector@<span style="color: #800000; ">0.0</span>.<span style="color: #800000; ">0.0</span>:<span style="color: #800000; ">8080</span></div> <div class="sqkw"><br /> 可以看出这个方式和第一种、第二种完全相同?/div> <div class="sqkw"></div> <div class="sqkw">另外start.jar提供了一种可以查看当前运行参数的命令?/div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->java -jar start.jar --dry-run</div> <div class="sqkw"><br /> 可能输出:</div> <div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->/opt/apps/jdk/bin/java -Djetty.home=/opt/apps/jetty8 -cp /opt/apps/jetty8/resources:\<br /> /opt/apps/jetty8/lib/jetty-xml-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:/opt/apps/jetty8/lib/servlet-api-<span style="color: #800000; ">3.0</span>.jar:\<br /> /opt/apps/jetty8/lib/jetty-http-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:/opt/apps/jetty8/lib/jetty-continuation-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:\<br /> /opt/apps/jetty8/lib/jetty-server-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:/opt/apps/jetty8/lib/jetty-security-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:\<br /> /opt/apps/jetty8/lib/jetty-servlet-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:/opt/apps/jetty8/lib/jetty-webapp-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:\<br /> /opt/apps/jetty8/lib/jetty-deploy-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:/opt/apps/jetty8/lib/jetty-servlets-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:\<br /> /opt/apps/jetty8/lib/jetty-util-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar:/opt/apps/jetty8/lib/jetty-io-<span style="color: #800000; ">8.1</span>.<span style="color: #800000; ">2</span>.v20120308.jar \<br /> org.eclipse.jetty.xml.XmlConfiguration /tmp/start1059041541723976621.properties /opt/apps/jetty8/etc/jetty.xml</div> <div class="sqkw"><br /> 有意思的是这里有一个临时文件:/tmp/start1059041541723976621.properties,里面记录了所有系统属性,也就是类似System.getProperties()?/div> <div class="sqkw">除非是嵌入式开发,否则我们都是用start.jar来启动jetty?/div> <h2 class="sqkw">命令参数</h2> <div class="sqkw">start.jar提供了大量的参数来负责启动JVM?/div> <div class="sqkw">下面命令列出所有的命令行参数:</div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->java -jar start.jar --help</div> <div class="sqkw"><br /> 现在问题来了,这些默认的参数都是哪来的?例如,如果想改变<em>${jetty.home}</em>又怎样?/div> <div class="sqkw">jetty内部默认提供了一个默认的配置文件<a target="_blank">start.config</a>来解决此问题?/div> <div class="sqkw">默认情况下start.jar里面带有一个默认的start.config文件,这个文件有一些预置的定义?/div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->[adyliu<span style="color: #800080; ">@adyliu</span>-pc jetty8]$ jar tvf start.jar | <span style="color: #0000FF; ">grep</span> start.config<br />   <span style="color: #800000; ">8669</span> Fri Mar <span style="color: #800000; ">09</span> <span style="color: #800000; ">00</span>:<span style="color: #800000; ">13</span>:<span style="color: #800000; ">12</span> CST <span style="color: #800000; ">2012</span> org/eclipse/jetty/start/start.config</div> <a target="_blank"><br /> start.config</a> 文件内容非常大,其中大部分是注释?br /> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">start.config的作用有以下几个?/p> <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "> <li class="sqkw">定义jetty.home属?/li> <li class="sqkw">定义jetty启动?/li> <li class="sqkw">定义jetty启动的默认配置文?/li> <li class="sqkw">定义OPTIONS</li> <li class="sqkw">根据OPTIONS来定义classpath</li> </ul> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">上面特别提到OPTIONS。什么是OPTIONS?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>OPTIONS</h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">由于jetty是高度可定制的,因此jetty将各个模块拆分成各个非常细小的模块。每一个模块(实际上是一个个的jar包),我们可以简单的看出是一个OPTION。而每一个OPTION都会对应于实际的jar,这就决定了这些jar包是否需要加入classpath,并且在jetty启动的时候是否需要做一些额外的事情?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">start.config文件的语法也挺有意思的。支持一些简单的逻辑判断,例如文件是否存在、命令行参数是否存在等?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">默认情况下有如下配置?/p> <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "> <li class="sqkw">path参数的值加入classpath</li> <li class="sqkw">lib参数的值作为目录搜索jar包,其中的jar/zip包加入classpath</li> <li class="sqkw">默认的启动类是org.eclipse.jetty.xml.XmlConfiguration.class,除非定义了start.class属?/li> <li class="sqkw">默认的jetty配置文件?(jetty.home)/etc/jetty.xml,除非传入的参数不为?/li> <li class="sqkw">默认${jetty.home}目录是当前目录(不一定是start.jar所在路径)?{jetty.home}属性搜索顺序有? <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; "> <li class="sqkw">$(jetty.home) 参数或者系统属性(包括环境变量?/li> <li class="sqkw">. 当前路径</li> <li class="sqkw">.. 当前路径的父路径</li> <li class="sqkw">jetty-distribution/src/main/resources 当前路径的发行版子路?/li> <li class="sqkw">../jetty-distribution/src/main/resources 当前路径的父路径的发行版子路?/li> </ul> </li> <li class="sqkw">默认的classpath有: <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; "> <li class="sqkw">resources</li> <li class="sqkw">lib/jetty-xml-8.1.2.v20120308.jar</li> <li class="sqkw">lib/servlet-api-3.0.jar</li> <li class="sqkw">lib/jetty-http-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-continuation-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-server-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-security-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-servlet-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-webapp-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-deploy-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-servlets-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-util-8.1.2.v20120308.jar</li> <li class="sqkw">lib/jetty-io-8.1.2.v20120308.jar</li> </ul> </li> </ul> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>start.jar参数</h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">我们再来看start.jar支持的参数:</p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->[adyliu<span style="color: #800080; ">@adyliu</span>-pc jetty8]<span style="color: #008000; ">#</span><span style="color: #008000; "> java -jar start.jar --help</span><span style="color: #008000; "><br /> </span>Usage: java -jar start.jar [options<img src="//www.hncyb.com/Images/dot.gif" alt="" />] [properties<img src="//www.hncyb.com/Images/dot.gif" alt="" />] [configs<img src="//www.hncyb.com/Images/dot.gif" alt="" />]</div> <br /> <h4>options</h4> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">其中options列表(这指的是命令行参数,不是模块,由此可见jetty将内置的OPTIONS定义为模块多好)有:</p> <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "> <li class="sqkw">--version 列出版本?/li> <li class="sqkw">--list-options 列出当前start.config支持的所有OPTIONS</li> <li class="sqkw">--list-config 列出当前start.config内容(文本内容)</li> <li class="sqkw">--dry-run 列出当前配置要启动的java进程完整参数(不启动jetty服务?/li> <li class="sqkw">--exec 启动子进程(只有启动子进程才能修?X?D等参数,因为start.jar本身就是依靠java进程启动的,不能在运行时改变?/li> <li class="sqkw">--stop 停止运行的jetty实例</li> <li class="sqkw">--daemon 后台运行jetty,启动将stdout/stderr记录?{jetty.log}/start.log中(好了,这个变量jetty.log没有默认配置说明,估计是${jetty.home}/logs目录?/li> <li class="sqkw">--config=<file> 指定特别的start.config,以便覆盖内置的start.config.(经过测试,如果指定此文件,那么内置的配置将不再读取,这导致必须将所有配置写全,包括mainclass/jetty config/OPTIONS等)</li> <li class="sqkw">--ini=<file> 从配置文件中装载命令行参数。上面参数以及下面提到的参数是在太多,可以从配置文件中一次性加载,默认的配置文件是${jetty.home}/start.ini?/li> <li class="sqkw">--pre=<file> 指定特别的jetty运行配置文件,这个配置文件在后面提高的配置文件前面运行,相当于改变默认的装载机制?/li> </ul> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h4>properties</h4> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">属性分成两种,一种是会传递给系统属性(java.lang.System#getProperty(String)),一种只是作为jetty的启动参数?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">如果要传递给系统属性,则格式是?-Dname=value,和java进程系统属性类似?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">jetty也有一些默认的系统属性:</p> <table border="1" width="80%" style="font-size: 15px; line-height: 19px; border-color: initial; background-image: none; background-attachment: scroll; background-origin: initial; background-clip: initial; background-color: #ffffff; border-collapse: collapse; color: #000000; font-family: Arial, Helvetica, sans-serif; background-position: 0px 0px; background-repeat: repeat repeat; "> <tbody> <tr> <th>属?/th><th>类型</th><th>描述</th> </tr> <tr> <td>org.eclipse.jetty.util.log.class</td> <td>class</td> <td>jetty日志记录,默认为:org.eclipse.jetty.util.log.Slf4jLog</td> </tr> <tr> <td>org.eclipse.jetty.util.log.DEBUG</td> <td>boolean</td> <td>调试日志输出地方,默认为stderr和java内置的Logger,如果是其他日志则需要设置为true,默认为false</td> </tr> <tr> <td>org.eclipse.jetty.util.log.IGNORED</td> <td>boolean</td> <td>是否记录一些忽略的错误日志,默认为false</td> </tr> <tr> <td>org.eclipse.jetty.util.log.SOURCE</td> <td>boolean</td> <td>记录错误日志行号?位置?默认为false</td> </tr> <tr> <td>com.sun.management.jmxremote</td> <td> </td> <td>启动jmx管理</td> </tr> </tbody> </table> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">jetty的启动参数属性,格式是: name=value,注意这里没?D了。这些参数不会传递给系统属性?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">所有参数列表:</p> <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "> <li class="sqkw">path=[directory]: 传递额外的classpath,参考上面默认的start.config配置</li> <li class="sqkw">lib=[directory]: 传递额外classpath搜索jar/zip的目?/li> <li class="sqkw">STOP.PORT=[number]: 停止jetty的端口(远程管理?/li> <li class="sqkw">STOP.KEY=[alphanumeric]: 停止jetty的密码(远程管理?/li> <li class="sqkw">DEBUG=true: 是否启动调试模式,同时会设置org.eclipse.jetty.util.log.DEBUG属性为true,默认为false</li> <li class="sqkw">OPTIONS=[option,option...]: OPTION列表,也就是要启动的模块列表?/li> </ul> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">在内置的start.config中默认的OPTIONS列表有:</p> <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "> <li class="sqkw">All</li> <li class="sqkw">Client</li> <li class="sqkw">Server</li> <li class="sqkw">ajp</li> <li class="sqkw">annotations</li> <li class="sqkw">client</li> <li class="sqkw">default</li> <li class="sqkw">deploy</li> <li class="sqkw">ext</li> <li class="sqkw">jmx</li> <li class="sqkw">jndi</li> <li class="sqkw">jsp</li> <li class="sqkw">jta</li> <li class="sqkw">monitor</li> <li class="sqkw">overlay</li> <li class="sqkw">overlays</li> <li class="sqkw">plus</li> <li class="sqkw">policy</li> <li class="sqkw">resources</li> <li class="sqkw">rewrite</li> <li class="sqkw">security</li> <li class="sqkw">server</li> <li class="sqkw">servlet</li> <li class="sqkw">servlets</li> <li class="sqkw">setuid</li> <li class="sqkw">webapp</li> <li class="sqkw">websocket</li> <li class="sqkw">xml</li> </ul> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h4>configs</h4> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">jetty运行需要一些配置文件,这些配置文件对应于不同的OPTION所需要的配置?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">默认的jetty配置存在都存在于${jetty.home}/etc中,所有配置文件列表有?/p> <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "> <li class="sqkw">etc/jetty-ajp.xml</li> <li class="sqkw">etc/jetty-annotations.xml</li> <li class="sqkw">etc/jetty-bio-ssl.xml</li> <li class="sqkw">etc/jetty-bio.xml</li> <li class="sqkw">etc/jetty-contexts.xml</li> <li class="sqkw">etc/jetty-debug.xml</li> <li class="sqkw">etc/jetty-deploy.xml</li> <li class="sqkw">etc/jetty-fileserver.xml</li> <li class="sqkw">etc/jetty-ipaccess.xml</li> <li class="sqkw">etc/jetty-jmx.xml</li> <li class="sqkw">etc/jetty-logging.xml</li> <li class="sqkw">etc/jetty-monitor.xml</li> <li class="sqkw">etc/jetty-overlay.xml</li> <li class="sqkw">etc/jetty-plus.xml</li> <li class="sqkw">etc/jetty-policy.xml</li> <li class="sqkw">etc/jetty-proxy.xml</li> <li class="sqkw">etc/jetty-requestlog.xml</li> <li class="sqkw">etc/jetty-rewrite.xml</li> <li class="sqkw">etc/jetty-ssl.xml</li> <li class="sqkw">etc/jetty-stats.xml</li> <li class="sqkw">etc/jetty-testrealm.xml</li> <li class="sqkw">etc/jetty-webapps.xml</li> <li class="sqkw">etc/jetty-xinetd.xml</li> <li class="sqkw">etc/jetty.xml</li> </ul> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">这么多配置,如何记得住?该使用哪些配置?</p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">下一个章节中介绍配置文件?br /> </p> <br /> 参考资源:<br /> <ul class="sqkw"> <li class="sqkw"><a href="//www.hncyb.com/xylz/archive/2012/03/09/371598.html" target="_blank">[深入浅出Jetty 03] 简单的RESTful入门</a></li> <li class="sqkw"><a href="//www.hncyb.com/xylz/archive/2012/01/29/368970.html" target="_blank">[深入浅出Jetty 02] Jetty 8.x 简单试?/a></li> <li class="sqkw"><a href="//www.hncyb.com/xylz/archive/2012/01/29/368969.html" target="_blank">[深入浅出Jetty 01] Jetty 8.x 安装</a></li> </ul><img src ="//www.hncyb.com/xylz/aggbug/372923.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2012-03-28 19:02 <a href="//www.hncyb.com/xylz/archive/2012/03/28/372923.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一次简单却致命的错?/title><link>//www.hncyb.com/xylz/archive/2012/03/15/371966.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Thu, 15 Mar 2012 10:30:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2012/03/15/371966.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/371966.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2012/03/15/371966.html#Feedback</comments><slash:comments>16</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/371966.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/371966.html</trackback:ping><description><![CDATA[线上服务器负载过高发生了报警,同事找我求救?br />我看到机器的负载都超?0了,查看java进程线程栈,找到了出问题的代码?br /> <br /> 下面是其代码片段,实际情况错误处理比这更坏?br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><span style="color: #008080; "> 1</span> <span style="color: #0000FF; ">package</span> demo;<br /> <span style="color: #008080; "> 2</span> <br /> <span style="color: #008080; "> 3</span> <span style="color: #0000FF; ">import</span> java.io.BufferedReader;<br /> <span style="color: #008080; "> 4</span> <span style="color: #0000FF; ">import</span> java.io.InputStream;<br /> <span style="color: #008080; "> 5</span> <span style="color: #0000FF; ">import</span> java.io.InputStreamReader;<br /> <span style="color: #008080; "> 6</span> <span style="color: #0000FF; ">import</span> java.net.HttpURLConnection;<br /> <span style="color: #008080; "> 7</span> <span style="color: #0000FF; ">import</span> java.net.URL;<br /> <span style="color: #008080; "> 8</span> <span style="color: #0000FF; ">import</span> java.net.URLConnection;<br /> <span style="color: #008080; "> 9</span> <span style="color: #0000FF; ">import</span> org.apache.commons.lang.StringUtils;<br /> <span style="color: #008080; ">10</span> <br /> <span style="color: #008080; ">11</span> <span style="color: #008000; ">/**</span><span style="color: #008000; "><br /> </span><span style="color: #008080; ">12</span> <span style="color: #008000; "> * </span><span style="color: #808080; ">@author</span><span style="color: #008000; "> adyliu (imxylz#gmail.com)<br /> </span><span style="color: #008080; ">13</span> <span style="color: #008000; "> * </span><span style="color: #808080; ">@since</span><span style="color: #008000; "> 2012-3-15<br /> </span><span style="color: #008080; ">14</span> <span style="color: #008000; "> </span><span style="color: #008000; ">*/</span><br /> <span style="color: #008080; ">15</span> <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> FaultDemo {<br /> <span style="color: #008080; ">16</span> <br /> <span style="color: #008080; ">17</span>     <span style="color: #008000; ">/**</span><span style="color: #008000; "><br /> </span><span style="color: #008080; ">18</span> <span style="color: #008000; ">     * </span><span style="color: #808080; ">@param</span><span style="color: #008000; "> args<br /> </span><span style="color: #008080; ">19</span> <span style="color: #008000; ">     </span><span style="color: #008000; ">*/</span><br /> <span style="color: #008080; ">20</span>     <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">void</span> main(String[] args) <span style="color: #0000FF; ">throws</span> Exception {<br /> <span style="color: #008080; ">21</span>         <span style="color: #0000FF; ">final</span> String tudou = "//v.youku.com/v_playlist/f17170661o1p9.html";<br /> <span style="color: #008080; ">22</span> <br /> <span style="color: #008080; ">23</span>         URL url = <span style="color: #0000FF; ">new</span> URL(tudou);<br /> <span style="color: #008080; ">24</span>         HttpURLConnection conn = (HttpURLConnection) url.openConnection();<br /> <span style="color: #008080; ">25</span>         conn.connect();<br /> <span style="color: #008080; ">26</span>         <span style="color: #0000FF; ">try</span> {<br /> <span style="color: #008080; ">27</span>             InputStream in = conn.getInputStream();<br /> <span style="color: #008080; ">28</span>             BufferedReader br = <span style="color: #0000FF; ">new</span> BufferedReader(<span style="color: #0000FF; ">new</span> InputStreamReader(in, "utf-8"));<br /> <span style="color: #008080; ">29</span>             StringBuilder buf = <span style="color: #0000FF; ">new</span> StringBuilder();<br /> <span style="color: #008080; ">30</span>             String line = <span style="color: #0000FF; ">null</span>;<br /> <span style="color: #008080; ">31</span>             <span style="color: #0000FF; ">while</span> ((line = br.readLine()) != <span style="color: #0000FF; ">null</span>) {<br /> <span style="color: #008080; ">32</span>                 <span style="color: #0000FF; ">if</span> (StringUtils.isNotEmpty(buf.toString())) {<br /> <span style="color: #008080; ">33</span>                     buf.append("\r\n");<br /> <span style="color: #008080; ">34</span>                 }<br /> <span style="color: #008080; ">35</span>                 buf.append(line);<br /> <span style="color: #008080; ">36</span>             }<br /> <span style="color: #008080; ">37</span>             <span style="color: #008000; ">//</span><span style="color: #008000; ">do something with 'buf'</span><span style="color: #008000; "><br /> </span><span style="color: #008080; ">38</span> <span style="color: #008000; "></span><br /> <span style="color: #008080; ">39</span>         } <span style="color: #0000FF; ">finally</span> {<br /> <span style="color: #008080; ">40</span>             conn.disconnect();<br /> <span style="color: #008080; ">41</span>         }<br /> <span style="color: #008080; ">42</span> <br /> <span style="color: #008080; ">43</span>     }<br /> <span style="color: #008080; ">44</span> <br /> <span style="color: #008080; ">45</span> }<br /> <span style="color: #008080; ">46</span> </div> <br /> 思考下,这段代码有什?strong style="background-color: yellow; ">致命</strong>问题么?(这里不追究业务逻辑处理的正确性以及细小的瑕疵?br /> .<br /> ..<br /> ...<br /> 现在回来?br /> 我发现线程栈里面的线程都RUNNABLE?2行?br /> 这一行看起来有什么问题呢?StringBuilder.toString()不是转换成String么?Apache commons-lang里面的StringUtils.isNotEmpty使用也没问题啊?<br /> 看代码,人家的逻辑其实是判断是否是第一行,如果不是第一行那么就增加一个换行符?br /> <br /> 既然CPU在这里运行,那么就说明这个地方一定存在非常耗费CPU的操作,导致CPU非常繁忙,从而系统负载过高?br /> 看详细堆栈,其实CPU在进行内存的拷贝动作?br /> 看下面的源码?br /> <em style="color: #0000ff; ">java.lang.StringBuilder.toString()</em><br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->    <span style="color: #0000FF; ">public</span> String toString() {<br />         <span style="color: #008000; ">//</span><span style="color: #008000; "> Create a copy, don't share the array</span><span style="color: #008000; "><br /> </span>    <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> String(value, 0, count);<br />     }</div> 接着看java.lang.String的构造函数:<br /> <div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->    <span style="color: #0000FF; ">public</span> String(<span style="color: #0000FF; ">char</span> value[], <span style="color: #0000FF; ">int</span> offset, <span style="color: #0000FF; ">int</span> count) {<br />         <span style="color: #0000FF; ">if</span> (offset < 0) {<br />             <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> StringIndexOutOfBoundsException(offset);<br />         }<br />         <span style="color: #0000FF; ">if</span> (count < 0) {<br />             <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> StringIndexOutOfBoundsException(count);<br />         }<br />         <span style="color: #008000; ">//</span><span style="color: #008000; "> Note: offset or count might be near -1>>>1.</span><span style="color: #008000; "><br /> </span>        <span style="color: #0000FF; ">if</span> (offset > value.length - count) {<br />             <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> StringIndexOutOfBoundsException(offset + count);<br />         }<br />         <span style="color: #0000FF; ">this</span>.offset = 0;<br />         <span style="color: #0000FF; ">this</span>.count = count;<br />         <span style="color: #0000FF; ">this</span>.value = Arrays.copyOfRange(value, offset, offset+count);<br />     }</div> <br /> 看出来了么?<br /> 问题的关键在于String构造函数的最后一行,value并不是直接指向的,而是重新生成了一个新的字符串,使用系统拷贝函数进行内存复制?br /> <div class="sqkw"><em style="color: #0000ff; ">java.util.Arrays.copyOfRange(char[], int, int)</em></div> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">char</span>[] copyOfRange(<span style="color: #0000FF; ">char</span>[] original, <span style="color: #0000FF; ">int</span> from, <span style="color: #0000FF; ">int</span> to) {<br />         <span style="color: #0000FF; ">int</span> newLength = to - from;<br />         <span style="color: #0000FF; ">if</span> (newLength < 0)<br />             <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> IllegalArgumentException(from + " > " + to);<br />         <span style="color: #0000FF; ">char</span>[] copy = <span style="color: #0000FF; ">new</span> <span style="color: #0000FF; ">char</span>[newLength];<br />         System.arraycopy(original, from, copy, 0,<br />                          Math.min(original.length - from, newLength));<br />         <span style="color: #0000FF; ">return</span> copy;<br />     }</div> <br /> 好了,再回头看逻辑代码32行?br /> <div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000FF; ">if</span> (StringUtils.isNotEmpty(buf.toString())) {<br />     buf.append("\r\n");<br /> }</div> 这里有问题的地方在于每次循环一行的时候都生成一个新的字符串。也就是说如果HTTP返回的结果输入流中有1000行的话,将额外生?000个字符串(不算StringBuilder扩容生成的个数)。每一个字符串还比前一个字符串大?br /> <br /> <br /> 我们来做一个简单的测试,我们在原来的代码上增加几行计数代码?br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->    <span style="color: #0000FF; ">int</span> lines =0;<br />     <span style="color: #0000FF; ">int</span> count = 0;<br />     <span style="color: #0000FF; ">int</span> malloc = 0;<br />     <span style="color: #0000FF; ">while</span> ((line = br.readLine()) != <span style="color: #0000FF; ">null</span>) {<br />         lines++;<br />         count+=line.length();<br />         malloc += count;<br />         <span style="color: #0000FF; ">if</span> (StringUtils.isNotEmpty(buf.toString())) {<br />             buf.append("\r\n");<br />         }<br />         buf.append(line);<br />     }<br />     System.out.println(lines+" -> "+count+" -> "+malloc);</div> 我们记录下行数lines以及额外发生的字符串拷贝大小malloc?br /> 这是一次输出的结果?br /> <div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->1169 -> 66958 -> 39356387</div> 也就?169行的网页,一共是66958字节?5KB),结果额外生成的内存大小(不算StringBuilder扩容占用的内存大小)?9356387字节?7.5MB)!!!<br /> 试想一下,CPU一直频繁于进行内存分配,机器的负载能不高么?我们线上服务器?个CPU 16核,内存24G的Redhat Enterprise Linux 5.5,负载居然达到几十。这还是只有访问量很低的时候。这就难怪服务频繁宕机了?br /> <br /> 事实上我们有非常完善和丰富的基于Apache commons-httpclient的封装,操作起来也非常简单。对于这种简单的请求,只需要一条命令就解决了?br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->String platform.utils.HttpClientUtils.getResponse(String)<br /> String platform.utils.HttpClientUtils.postResponse(String, Map<String, String>)</div> <br /> 即使非要自造轮子,处理这种简单的输入流可以使用下面的代码,就可以很好的解决问题?br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->    InputStream in = <img src="//www.hncyb.com/Images/dot.gif" alt="" /><br />     ByteArrayOutputStream baos = <span style="color: #0000FF; ">new</span> ByteArrayOutputStream(8192);<br />     <span style="color: #0000FF; ">int</span> len = -1;<br />     <span style="color: #0000FF; ">byte</span>[] b = <span style="color: #0000FF; ">new</span> <span style="color: #0000FF; ">byte</span>[8192];<span style="color: #008000; ">//</span><span style="color: #008000; ">8k</span><span style="color: #008000; "><br /> </span>    <span style="color: #0000FF; ">while</span> ((len = in.read(b)) > 0) {<br />         baos.write(b, 0, len);<br />     }<br />     baos.close();<span style="color: #008000; ">//</span><span style="color: #008000; ">ignore is ok</span><span style="color: #008000; "><br /> </span>    String response =  <span style="color: #0000FF; ">new</span> String(baos.toByteArray(), encoding);</div> <br /> 当然了,最后紧急处理线上问题最快的方式就是将有问题的代码稍微变通下即可?br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->    <span style="color: #0000FF; ">if</span> (<strong style="background-color: yellow; ">buf.length() > 0</strong>) {<br />         buf.append("\r\n");<br />     }</div> <br /> <br /> 这个问题非常简单,只是想表达几个观点:<br /> <ul class="sqkw"> <li class="sqkw">团队更需要合作,按照规范来进行。自造轮子不是不可以,但是生产环境还是要限于自己熟悉的方式?/li> <li class="sqkw">即使非常简单的代码,也有可能有致命的陷阱在里面。善于思考才是王道?/li> <li class="sqkw">学习开源的代码和常规思路,学习解决问题的常规做法。这个问题其实非常简单,熟悉输入输出流的人非常熟练就能解决问题?/li> </ul><img src ="//www.hncyb.com/xylz/aggbug/371966.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2012-03-15 18:30 <a href="//www.hncyb.com/xylz/archive/2012/03/15/371966.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[深入浅出Jetty 03]简单的RESTful入门 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/03/09/371598.htmlimxylzimxylzFri, 09 Mar 2012 09:52:00 GMT//www.hncyb.com/xylz/archive/2012/03/09/371598.html//www.hncyb.com/xylz/comments/371598.html//www.hncyb.com/xylz/archive/2012/03/09/371598.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/371598.html//www.hncyb.com/xylz/services/trackbacks/371598.html
    项目地址?a >https://github.com/adyliu/jetty-rest-demo 

    文件列表


    包含如下文件?/p>

    • git忽略文件
    • README文件
    • pom文件
    • 一个简单的Controller文件
    • 一个log4j的配置文?/li>
    • 一个简单的spring mvc配置
    • 一个简单的web.xml

    Maven配置

    为了能够方便从jetty:run来启动web容器,使用jetty的maven插件?br />需要特别注意的是,从jetty7.5.3开始就必须用maven 3了,以前使用的maven 2不能使用了,就为了这问题,我跟踪了很久,大囧?br />这里使用jetty最新的maven插件,同样会启动最新的jetty8.1.1 来测试?br />
    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.1.v20120215</version>
            </plugin>
        </plugins>
    </build>

    web.xml

    这是一个简单的web.xml配置,主要配置spring servlet。当然这里也辅助配置了一个log4j,方便查看日志输出,不配置也没关系?br />另外也没有使用servlet 3.0的配置?br />
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="//java.sun.com/xml/ns/j2ee" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="//java.sun.com/xml/ns/j2ee //java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version
    ="2.4">
        <display-name>jetty-rest-demo</display-name>
        <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>classpath:log4j.properties</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
    </web-app>

    dispatcher-servlet.xml

    接下来是spring mvc的配置?br />包含三部分:要扫描的住解包,mvc注解驱动以及jsp的渲染映射(其实这个例子中没有用到)?br />
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="//www.springframework.org/schema/beans" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
        xmlns:context
    ="//www.springframework.org/schema/context" xmlns:mvc="//www.springframework.org/schema/mvc"
        xsi:schemaLocation
    ="//www.springframework.org/schema/beans //www.springframework.org/schema/beans/spring-beans-3.1.xsd
                //www.springframework.org/schema/context //www.springframework.org/schema/context/spring-context-3.1.xsd
                //www.springframework.org/schema/mvc //www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"
    >
        <context:component-scan base-package="info.imxylz.study.jetty.rest" />
        <mvc:annotation-driven />
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/pages/"></property>
            <property name="suffix" value=".jsp"></property>
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
        </bean>
    </beans>

    Controller

    下载开始写第一个Controller,当然这个Controller稍微有一点点别扭?br />直接返回字符串,另外将索引页映射到一个字符串上。(也不对中文进行处理)

    package info.imxylz.study.jetty.rest.controller;

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;

    /**
     * a rest demo (spring 3.x)
     * 
     * 
    @author adyliu (imxylz@gmail.com)
     * 
    @since 2012-3-9
     
    */
    @Controller
    public class DemoController {

        @ResponseBody
        @RequestMapping("/index/{name}/")
        public String index(@PathVariable("name") String name) {
            return "Welcome, " + name;
        }
        @ResponseBody
        @RequestMapping("")
        public String index() {
            return "This is a rest demo";
        }
    }

    Access

    现在该是打开浏览器显示下了?br />
    //localhost:8080/index/Ady/
    //localhost:8080/index/Ady%20Liu/
    //localhost:8080/

    好了,这算是一个最简单的入门例子了?br />下面的参考资源中有git的源码?br />

    Resources



    imxylz 2012-03-09 17:52 发表评论
    ]]>
    ICE Mini Guide - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/02/29/370971.htmlimxylzimxylzWed, 29 Feb 2012 02:44:00 GMT//www.hncyb.com/xylz/archive/2012/02/29/370971.html//www.hncyb.com/xylz/comments/370971.html//www.hncyb.com/xylz/archive/2012/02/29/370971.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/370971.html//www.hncyb.com/xylz/services/trackbacks/370971.htmlICE中间件?br />
    ICE作为一个异构平台,提供了高性能的RPC解决方案。全年指定的架构计划中就是将现有的内部通讯方式迁移到ICE+Protocol Buffers的组合方案中?br /> 我们尽可能的利用Zookeeper的配置管理,创建更透明的客户端代理,同时也是降低开发的难度?br /> 我们慢慢尝试,寻找更适合我们的分布式通讯中间件?br />
    下面的Slide是一篇简短的入门介绍。目前为止,我们的开发还是仅限于Java语言的服务端。以后视情况提供一些其它语言的服务端吧?br /> 关键字:ICE "The Internet Communications Engine" RPC "Protocol Buffers"

    imxylz 2012-02-29 10:44 发表评论
    ]]>
    搜狐技术部长期招聘Java工程?高级工程?初级架构?项目经理/技术主?/title><link>//www.hncyb.com/xylz/archive/2012/02/16/366663.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Thu, 16 Feb 2012 03:10:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2012/02/16/366663.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/366663.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2012/02/16/366663.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/366663.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/366663.html</trackback:ping><description><![CDATA[<div class="sqkw"><span style="font-size: 12pt; ">业务发展需要,对人才的渴望,对事业的追求,搜狐技术部需要一些高级人才?/span><br /> <span style="font-size: 12pt; "> 今年社招努力不再拘于形式,只要是人才,双方有意愿的,我们都努力去争取?/span><br /> <br /> <span style="font-size: 12pt; ">北京地点:北?五道?/span><br /> <span style="font-size: 12pt; ">工作经验:不限,应届生都可以,我们有工作十年以上的人才,也需要这种人才?/span><br /> <span style="font-size: 12pt; "> 待遇方面:努力跟上物价的水平。常规在10K~30K?/span><br /> <span style="font-size: 12pt; "> 技术要求:以Java语言为主,要求对基本的技术、概念、理论、框架都需要有一定的深度。根据经验,仅仅是靠忽悠和项目数量是不行的?/span><br /> <span style="font-size: 12pt; "> 产品要求:要求对主流的互联网产品都有认识,对用户体验有一定的理解。对于非应届生,我们更偏重于用互联网技术经验(不是企业WEB系统方面)?/span><br /> <span style="font-size: 12pt; "> 扩展要求:要求有gmail/twitter/stackoverflow/github帐号。有开源贡献的特别考虑?/span><br /> <span style="font-size: 12pt; "> 创新要求:能够掌握python/ruby/perl/Erlang等一两种脚本语言为佳?/span><br /> <span style="font-size: 12pt; "> 工作领域:我们有挑战的领域有大规模数据集群、高性能异步通讯、海量数据处理、分布式存储与缓存、并行计算、高并发处理等?/span><br /> <br /> <br /> <span style="font-size: 12pt; ">我们欢迎有志向于互联网的同学加入。技术要求不高,但要有思想、有深度、热爱互联网?/span><br /> <span style="font-size: 12pt; ">有兴趣发送简历到?/span><span style="font-size: 12pt; color: #ff0000; "><strong class="sqkw">已过?/strong></span><br /> <br /> <br /> <span style="font-size: 12pt; ">我们长期招聘这类人才,只要是人才,我们都愿意提供相适应的环境?br /><strong class="sqkw">另外,也非常需要一个前端主管,负责管理整个团队的前端技术人才和基础架构?/strong><br /><strike>【最后更新时间:2012/11/01?br /></strike><br /></span></div><img src ="//www.hncyb.com/xylz/aggbug/366663.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2012-02-16 11:10 <a href="//www.hncyb.com/xylz/archive/2012/02/16/366663.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring Framework 3.1 Reference CHM - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/02/08/369608.htmlimxylzimxylzWed, 08 Feb 2012 08:41:00 GMT//www.hncyb.com/xylz/archive/2012/02/08/369608.html//www.hncyb.com/xylz/comments/369608.html//www.hncyb.com/xylz/archive/2012/02/08/369608.html#Feedback1//www.hncyb.com/xylz/comments/commentRss/369608.html//www.hncyb.com/xylz/services/trackbacks/369608.html
    去掉了发生错误的javascript(网络原因,你懂的),索引排序重命名,稍微排版了下?br />
    没有改动任何内容?strong style="font-family: 'Comic Sans MS'; font-size: 14pt; color: #0000ff; ">毫无疑问,这是英文版的,因为没有人翻译?/strong>

    截图如下?br />

    Spring Framework 3.1 Reference CHM
    SpringFramework3.1-Reference_en.chm

    imxylz 2012-02-08 16:41 发表评论
    ]]>
    [深入浅出Jetty 02] Jetty 8.x 简单试?/title><link>//www.hncyb.com/xylz/archive/2012/01/29/368970.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Sun, 29 Jan 2012 08:41:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2012/01/29/368970.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/368970.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2012/01/29/368970.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/368970.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/368970.html</trackback:ping><description><![CDATA[<h1 class="sqkw">Jetty 8.x 简单试?/h1><h2 class="sqkw">运行</h2><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">安装好了以后,在jetty的主目录下,运行起来?/p><pre style="font-size: 1.2em; font-family: 'Lucida Console', 'Andale Mono', 'Courier New', Courier, monospace; line-height: 1.2em; margin-top: 2px; margin-bottom: 2px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-color: initial; border-image: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9f9; overflow-x: auto; overflow-y: auto; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-right: 2px; margin-left: 2px; ">java -jar start.jar </pre><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">如果仔细看的话还有一个start.ini,这是典型的eclipse启动方式。事实上jetty8是按照eclipse的OSGI启动模型来运行的?/p><div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div><h2 class="sqkw">远程访问</h2><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">默认情况下jetty使用8080端口,访问下看看?/p><pre style="font-size: 1.2em; font-family: 'Lucida Console', 'Andale Mono', 'Courier New', Courier, monospace; line-height: 1.2em; margin-top: 2px; margin-bottom: 2px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-color: initial; border-image: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f9f9f9; overflow-x: auto; overflow-y: auto; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; margin-right: 2px; margin-left: 2px; ">//adyliu-pc:8080 </pre><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">出现了点问题。启动后居然是jetty7后的描述信息。看来jetty8发布的时候比较粗糙,这些细节都没有处理好。事实上,官方站点上的文章都是和jetty7.x有关的,没有更新?.x版本?br /><img src="//www.hncyb.com/images/blogjava_net/xylz/jetty01.png" width="949" height="391" alt="" /><br /></p><p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">好在有一行提示说,如果要远程访问的话,需要开启一个设置。好吧,按照说明,将默认test.war的远程访问模式打开?修改文件$JETTY_HOME/contexts/test.d/override-web.xml中的如下部分<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />//www.CodeHighlighter.com/<br /><br />-->  <span style="color: #0000FF; "><</span><span style="color: #800000; ">filter</span><span style="color: #0000FF; ">></span><br />    <span style="color: #0000FF; "><</span><span style="color: #800000; ">filter-name</span><span style="color: #0000FF; ">></span>TestFilter<span style="color: #0000FF; "></</span><span style="color: #800000; ">filter-name</span><span style="color: #0000FF; ">></span><br />    <span style="color: #0000FF; "><</span><span style="color: #800000; ">filter-class</span><span style="color: #0000FF; ">></span>com.acme.TestFilter<span style="color: #0000FF; "></</span><span style="color: #800000; ">filter-class</span><span style="color: #0000FF; ">></span><br />    <span style="color: #0000FF; "><</span><span style="color: #800000; ">init-param</span><span style="color: #0000FF; ">></span><br />      <span style="color: #0000FF; "><</span><span style="color: #800000; ">param-name</span><span style="color: #0000FF; ">></span>remote<span style="color: #0000FF; "></</span><span style="color: #800000; ">param-name</span><span style="color: #0000FF; ">></span><br />      <span style="color: #0000FF; "><</span><span style="color: #800000; ">param-value</span><span style="color: #0000FF; ">></span>true<span style="color: #0000FF; "></</span><span style="color: #800000; ">param-value</span><span style="color: #0000FF; ">></span><br />    <span style="color: #0000FF; "></</span><span style="color: #800000; ">init-param</span><span style="color: #0000FF; ">></span><br />  <span style="color: #0000FF; "></</span><span style="color: #800000; ">filter</span><span style="color: #0000FF; ">></span></div><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br />这里已经将默认remote的属性值false改为了true。然后再试试?/p><div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div><div style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br /><img src="//www.hncyb.com/images/blogjava_net/xylz/jetty02.png" width="959" height="485" alt="" /></div><p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">显然,这样就已经支持远程访问了?/p><div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div><h2 class="sqkw">Servlet访问</h2><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">test.war模块里面有一个dump的Servlet,它可以查看当前请求的Request/Session/Cookie信息。我们简单看一下Request请求?br /><br /></p><div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div><div style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><img src="//www.hncyb.com/images/blogjava_net/xylz/jetty03.png" width="900" height="609" alt="" /></div><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">这里面的信息非常丰富,这为以后调试当前请求信息提供了很方便的样例?/p><div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div><h2 class="sqkw">Comet模型</h2><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">Jetty8.x里面有两种comet模型,一种是常见的长连接(Long Polling), 另一种就是HTML5支持的WebSocket模型?/p><p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">我们先来简单看一下Long Polling模型。在这种方式下,浏览器定时发起一个长连接,等待服务器返回。一次请求完了以后仍然会发起一个新的请求,总是有一个连接保持双方的通讯?下图描述了此效果?br /><img src="//www.hncyb.com/images/blogjava_net/xylz/jetty-long-polling.png" width="717" height="505" alt="" /><br /></p><p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">而WebSocket模型显然不是所有浏览器都支持的。高版本的Chrome就支持,比如我的chrome 18.0的开发版本就能很好的支持WebSocket?br /><img src="//www.hncyb.com/images/blogjava_net/xylz/jetty-websocket.png" width="721" height="380" alt="" /><br /></p><p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">有意思的是,这里的请求头和响应头有一些特殊的标识。以后涉及到websocket的时候再来研究?br /><img src="//www.hncyb.com/images/blogjava_net/xylz/jetty-websocket-headers.png" width="622" height="341" alt="" /><br /></p><p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">经测试,我机器上的chrome 18.0,firefox 8.0都支持websocket的,而IE9仍然不支持?br /><br /><img src="//www.hncyb.com/images/blogjava_net/xylz/jetty-firefox.png" alt="" /><br /></p><img src ="//www.hncyb.com/xylz/aggbug/368970.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2012-01-29 16:41 <a href="//www.hncyb.com/xylz/archive/2012/01/29/368970.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[深入浅出Jetty 01] Jetty 8.x 安装 - 3d走势图综合版//www.hncyb.com/xylz/archive/2012/01/29/368969.htmlimxylzimxylzSun, 29 Jan 2012 08:34:00 GMT//www.hncyb.com/xylz/archive/2012/01/29/368969.html//www.hncyb.com/xylz/comments/368969.html//www.hncyb.com/xylz/archive/2012/01/29/368969.html#Feedback0//www.hncyb.com/xylz/comments/commentRss/368969.html//www.hncyb.com/xylz/services/trackbacks/368969.htmlJetty?.x已经迁移到eclipse下了,从eclipse的下载目录开始安装吧?/p>

    最新的发布版本?.1.0.v20120127,我们从这个版本开始?br />

    JETTY_VERSION=8.1.0.v20120127
    wget http://download.eclipse.org/jetty/$JETTY_VERSION/dist/jetty-distribution-$JETTY_VERSION.tar.gz
    tar xfz jetty-distribution-$JETTY_VERSION.tar.gz
    cd jetty-distribution-$JETTY_VERSION
    java -jar start.jar

    附录

    • 下载地址?a rel="nofollow" style="text-decoration: none; ">//download.eclipse.org/jetty/8.1.0.v20120127/dist/jetty-distribution-8.1.0.v20120127.tar.gz
    • 更多下载安装方式://wiki.eclipse.org/Jetty/Starting/Downloads


    imxylz 2012-01-29 16:34 发表评论
    ]]>
    深入浅出 Java Concurrency (40): 并发总结 part 4 性能与伸缩?/title><link>//www.hncyb.com/xylz/archive/2011/12/31/367641.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Sat, 31 Dec 2011 06:13:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2011/12/31/367641.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/367641.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2011/12/31/367641.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/367641.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/367641.html</trackback:ping><description><![CDATA[<h1 class="sqkw">性能与伸缩?/h1> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">使用线程的一种说法是为了提高性能。多线程可以使程序充分利用闲置的资源,提高资源的利用率,同时能够并行处理任务,提高系统的响应性?但是很显然,引入线程的同时也引入了系统的复杂性。另外系统的性能并不是总是随着线程数的增加而总是提高?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">性能与伸缩?/h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">性能的提升通常意味着可以用更少的资源做更多的事情。这里资源是包括我们常说的CPU周期、内存、网络带宽、磁盘IO、数据库、WEB服务等等?引入多线程可以充分利用多核的优势,充分利用IO阻塞带来的延迟,也可以降低网络开销带来的影响,从而提高单位时间内的响应效率?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">为了提高性能,需要有效的利用我们现有的处理资源,同时也要开拓新的可用资源。例如,对于CPU而言,理想状况下希望CPU能够满负荷工作。当然这里满负荷工作是指做有用的事情,而不是无谓的死循环或者等待。受限于CPU的计算能力,如果CPU达到了极限,那么很显然我们充分利用了计算能力。对于IO而言(内存、磁盘、网络等),如果达到了其对于的带宽,这些资源的利用率也就上去了。理想状况下所有资源的能力都被用完了,那么这个系统的性能达到了最大值?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">为了衡量系统的性能,有一些指标用于定性、定量的分析。例如服务时间、等待时间、吞吐量、效率、可伸缩性、生成量等等。服务时间、等待时间等用于衡量系统的效率,即到底有多快。吞吐量、生成量等用于衡量系统的容量,即能够处理多少数据。除此之外,有效服务时间、中断时间等用于能力系统的可靠性和稳定性等?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">可伸缩性的意思是指增加计算资源,吞吐量和生产量相应得到的改进?从算法的角度讲,通常用复杂度来衡量其对应的性能。例如时间复杂度、空间复杂度等?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">Amdahl定律</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">并行的任务增加资源显然能够提高性能,但是如果是串行的任务,增加资源并不一定能够得到合理的性能提升?nbsp;<a rel="nofollow" style="text-decoration: none; ">Amdahl定律</a>描述的在一个系统中,增加处理器资源对系统行的提升比率?假定在一个系统中,F是必须串行化执行的比重,N是处理器资源,那么随着N的增加最多增加的加速比?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <div style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><img src="//www.hncyb.com/images/blogjava_net/xylz/amdahl.png" width="200" height="71" alt="" /></div> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">理论上,当N趋近于无穷大时,加速比最大值无限趋近于1/F?这意味着如果一个程序的串行化比重为50%,那么并行化后最大加速比?倍?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">加速比除了可以用于加速的比率外,也可以用于衡量CPU资源的利用率。如果每一个CPU的资源利用率?00%,那么CPU的资源每次翻倍时,加速比也应该翻倍?事实上,在拥?0个处理器的系统中,程序如果有10%是串行化的,那么最多可以加?/(0.1+(1-0.1)/10)=5.3倍,换句话说CPU的利用率只用5.3/10=53%。而如果处理器增加?00倍,那么加速比?.2倍,也就是说CPU的利用率只有?.3%?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">显然增加CPU的数量并不能提高CPU的利用率。下图描述的是随着CPU的数量增加,不同串行化比重的系统的加速比?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <div style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><img src="//www.hncyb.com/images/blogjava_net/xylz/utilization.png" width="495" height="306" alt="" /></div> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">很显然,串行比重越大,增加CPU资源的效果越不明显?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">性能提升</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">性能的提升可以从以下几个方面入手?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>系统平台的资源利用率</h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">一个程序对系统平台的资源利用率是指某一个设备繁忙且服务于此程序的时间占所有时间的比率。从物理学的角度讲类似于有用功的比率。简单的说就是:资源利用?有效繁忙时间/总耗费时间?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">也就说尽可能的让设备做有用的功,同时榨取其最大值。无用的循环可能会导致CPU 100%的使用率,但不一定是有效的工作。有效性通常难以衡量,通常只能以主观来评估,或者通过被优化的程序的行为来判断是否提高了有效性?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>延迟</h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">延迟描述的是完成任务所耗费的时间。延迟有时候也成为响应时间。如果有多个并行的操作,那么延迟取决于耗费时间最大的任务?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>多处?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">多处理是指在单一系统上同时执行多个进程或者多个程序的能力。多处理能力的好处是可以提高吞吐量。多处理可以有效利用多核CPU的资源?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>多线?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">多线程描述的是同一个地址空间内同时执行多个线程的过程。这些线程都有不同的执行路径和不同的栈结构。我们说的并发性更多的是指针对线程?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>并发?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">同时执行多个程序或者任务称之为并发。单程序内的多任务处理或者多程序间的多任务处理都认为是并发?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>吞吐?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">吞吐量衡量系统在单位之间内可以完成的工作总量。对于硬件系统而言,吞吐量是物理介质的上限。在没有达到物理介质之前,提高系统的吞吐量也可以大幅度改进性能。同时吞吐量也是衡量性能的一个指标?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>瓶颈</h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">程序运行过程中性能最差的地方。通常而言,串行的IO、磁盘IO、内存单元分配、网络IO等都可能造成瓶颈。某些使用太频繁的算法也有可能成为瓶颈?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>可扩展?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">这里的可扩展性主要是指程序或系统通过增加可使用的资源而增加性能的能力?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">线程开销</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">假设引入的多线程都用于计算,那么性能一定会有很大的提升么? 其实引入多线程以后也会引入更多的开销?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>切换上下?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">如果可运行的线程数大于CPU的内核数,那么OS会根据一定的调度算法,强行切换正在运行的线程,从而使其它线程能够使用CPU周期?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">切换线程会导致上下文切换。线程的调度会导致CPU需要在操作系统和进程间花费更多的时间片段,这样真正执行应用程序的时间就减少了。另外上下文切换也会导致缓存的频繁进出,对于一个刚被切换的线程来说,可能由于高速缓冲中没有数据而变得更慢,从而导致更多的IO开销?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>内存同步</h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">不同线程间要进行数据同步,synchronized以及volatile提供的可见性都会导致缓存失效。线程栈之间的数据要和主存进行同步,这些同步有一些小小的开销。如果线程间同时要进行数据同步,那么这些同步的线程可能都会受阻?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>阻塞</h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">当发生锁竞争时,失败的线程会导致阻塞。通常阻塞的线程可能在JVM内部进行自旋等待,或者被操作系统挂起。自旋等待可能会导致更多的CPU切片浪费,而操作系统挂起则会导致更多的上下文切换?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">了解了性能的提升的几个方面,也了解性能的开销后,应用程序就要根据实际的场景进行取舍和评估。没有一劳永逸的优化方案,不断的进行小范围改进和调整是提高性能的有效手段。当前一些大的架构调整也会导致较大的性能的提升?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">简单的原则是在保证逻辑正确的情况小,找到性能瓶颈,小步改进和优化?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">参考资?/h2> <ul style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "> <li class="sqkw">Amdahl's law: <a rel="nofollow" style="text-decoration: none; ">//en.wikipedia.org/wiki/Amdahl%27s_law</a></li> <li class="sqkw">Gustafson's law: <a rel="nofollow" style="text-decoration: none; ">//en.wikipedia.org/wiki/Gustafson%27s_law</a></li> <li class="sqkw">Sun-Ni law: <a rel="nofollow" style="text-decoration: none; ">//en.wikipedia.org/wiki/Sun-Ni_law</a></li> <li class="sqkw">多核系统中三种典型锁竞争的加速比分析 <a rel="nofollow" style="text-decoration: none; ">//blog.csdn.net/drzhouweiming/article/details/1800319</a></li> <li class="sqkw">阿姆达尔定律和Gustafson定律的等价?nbsp;<a rel="nofollow" style="text-decoration: none; ">//book.51cto.com/art/201004/197506.htm</a></li> </ul> <p> </p> <div id="index"> <div id="previous"><a href="//www.hncyb.com/xylz/archive/2011/12/30/367592.html">并发总结 part 3 常见的并发陷?/a> </div> <div id="center" align="center"><a href="//www.hncyb.com/xylz/archive/2010/07/08/325587.html"><strong class="sqkw">?nbsp;  ?/strong></a> </div> <div id="next"><a name="over">暂时完结</a></div> </div><img src ="//www.hncyb.com/xylz/aggbug/367641.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2011-12-31 14:13 <a href="//www.hncyb.com/xylz/archive/2011/12/31/367641.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入浅出 Java Concurrency (39): 并发总结 part 3 常见的并发陷?/title><link>//www.hncyb.com/xylz/archive/2011/12/30/367592.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Fri, 30 Dec 2011 09:25:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2011/12/30/367592.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/367592.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2011/12/30/367592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/367592.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/367592.html</trackback:ping><description><![CDATA[<h1 class="sqkw">常见的并发陷?/h1> <h2 class="sqkw">volatile</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">volatile只能强调数据的可见性,并不能保证原子操作和线程安全,因此volatile不是万能的。参?a href="//www.hncyb.com/xylz/archive/2010/07/03/325168.html" rel="nofollow" style="text-decoration: none; ">指令重排?/a></p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">volatile最常见于下面两种场景?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">a. 循环检测机?br /> </p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000FF; ">volatile</span> <span style="color: #0000FF; ">boolean</span> done = <span style="color: #0000FF; ">false</span>;<br /> <img src="//www.hncyb.com/Images/dot.gif" alt="" /><br /> <br />     <span style="color: #0000FF; ">while</span>( ! done ){<br />         dosomething();<br />     }</div> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br /> b. 单例模型 ?a href="//www.hncyb.com/xylz/archive/2009/12/18/306622.html%ef%bc%89" rel="nofollow" style="text-decoration: none; ">//www.hncyb.com/xylz/archive/2009/12/18/306622.html?br /> <br /> </a></p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><a href="//www.hncyb.com/xylz/archive/2009/12/18/306622.html%ef%bc%89" rel="nofollow" style="text-decoration: none; "><span style="color: #0000FF; ">public</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">class</span><span style="color: #000000; "> DoubleLockSingleton {<br /> <br />     </span><span style="color: #0000FF; ">private</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">static</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">volatile</span><span style="color: #000000; "> DoubleLockSingleton instance </span><span style="color: #000000; ">=</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">;<br /> <br />     </span><span style="color: #0000FF; ">private</span><span style="color: #000000; "> DoubleLockSingleton() {<br />     }<br /> <br />     </span><span style="color: #0000FF; ">public</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">static</span><span style="color: #000000; "> DoubleLockSingleton getInstance() {<br />         </span><span style="color: #0000FF; ">if</span><span style="color: #000000; "> (instance </span><span style="color: #000000; ">==</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">) {<br />             </span><span style="color: #0000FF; ">synchronized</span><span style="color: #000000; "> (DoubleLockSingleton.</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">) {<br />                 </span><span style="color: #0000FF; ">if</span><span style="color: #000000; "> (instance </span><span style="color: #000000; ">==</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">null</span><span style="color: #000000; ">) {<br />                     instance </span><span style="color: #000000; ">=</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">new</span><span style="color: #000000; "> DoubleLockSingleton();<br />                 }<br />             }<br />         }<br />         </span><span style="color: #0000FF; ">return</span><span style="color: #000000; "> instance;<br />     }<br /> }</span></a></div> <p> </p> <h2 class="sqkw"><br /> synchronized/Lock</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">看起来Lock有更好的性能以及更灵活的控制,是否完全可以替换synchronized?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">?a href="//www.hncyb.com/xylz/archive/2010/07/16/326246.html" rel="nofollow" style="text-decoration: none; ">锁的一些其它问?/a>中说过,synchronized的性能随着JDK版本的升级会越来越高,而Lock优化的空间受限于CPU的性能,很有限。另外JDK内部的工具(线程转储)对synchronized是有一些支持的(方便发现死锁等),而对Lock是没有任何支持的?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">也就说简单的逻辑使用synchronized完全没有问题,随着机器的性能的提高,这点开销是可以忽略的。而且从代码结构上讲是更简单的。简单就是美?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">对于复杂的逻辑,如果涉及到读写锁、条件变量、更高的吞吐量以及更灵活、动态的用法,那么就可以考虑使用Lock。当然这里尤其需要注意Lock的正确用法?br /> </p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->Lock lock = <img src="//www.hncyb.com/Images/dot.gif" alt="" /><br /> lock.lock();<br /> <span style="color: #0000FF; ">try</span>{<br />     <span style="color: #008000; ">//</span><span style="color: #008000; ">do something</span><span style="color: #008000; "><br /> </span>}<span style="color: #0000FF; ">finally</span>{<br />     lock.unlock();<br /> }</div> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br /> 一定要将Lock的释放放入finally块中,否则一旦发生异常或者逻辑跳转,很有可能会导致锁没有释放,从而发生死锁。而且这种死锁是难以排查的?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">如果需要synchronized无法做到的尝试锁机制,或者说担心发生死锁无法自恢复,那么使用tryLock()是一个比较明智的选择的?br /> </p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->Lock lock = <img src="//www.hncyb.com/Images/dot.gif" alt="" /><br /> <span style="color: #0000FF; ">if</span>(lock.tryLock()){<br />     <span style="color: #0000FF; ">try</span>{<br />         <span style="color: #008000; ">//</span><span style="color: #008000; ">do something</span><span style="color: #008000; "><br /> </span>    }<span style="color: #0000FF; ">finally</span>{<br />         lock.unlock();<br />     }<br /> }</div> <p> </p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">甚至可以使用获取锁一段时间内超时的机制Lock.tryLock(long,TimeUnit)?锁的使用可以参考前面文章的描述和建议?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">锁的边界</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">一个流行的错误是这样的?br /> </p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->ConcurrentMap<String,String> map = <span style="color: #0000FF; ">new</span> ConcurrentHashMap<String,String>();<br /> <br /> <span style="color: #0000FF; ">if</span>(!map.containsKey(key)){<br />     map.put(key,value);<br /> }</div> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br /> 看起来很合理的,对于一个线程安全的Map实现,要存取一个不重复的结果,先检测是否存在然后加入?其实我们知道两个原子操作和在一起的指令序列不代表就是线程安全的?割裂的多个原子操作放在一起在多线程的情况下就有可能发生错误?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">实际上ConcurrentMap提供了putIfAbsent(K, V)?#8220;原子操作”机制,这等价于下面的逻辑?br /> </p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000FF; ">if</span>(map.containsKey(key)){<br />     <span style="color: #0000FF; ">return</span> map.get(key);<br /> }<span style="color: #0000FF; ">else</span>{<br />     <span style="color: #0000FF; ">return</span> map.put(k,v);<br /> }</div> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br /> 除了putIfAbsent还有replace(K, V)以及replace(K, V, V)两种机制来完成组合的操作?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">提到Map,这里有一篇谈<a href="//www.hncyb.com/xylz/archive/2009/12/18/306602.html" rel="nofollow" style="text-decoration: none; ">HashMap读写并发</a>的问题?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">构造函数启动线?/h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">下面的实例是在构造函数中启动一个线程?br /> </p> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> Runner{<br />    <span style="color: #0000FF; ">int</span> x,y;<br />    Thread thread;<br />    <span style="color: #0000FF; ">public</span> Runner(){<br />       <span style="color: #0000FF; ">this</span>.x=1;<br />       <span style="color: #0000FF; ">this</span>.y=2;<br />       <span style="color: #0000FF; ">this</span>.thread=<span style="color: #0000FF; ">new</span> MyThread();<br />       <span style="color: #0000FF; ">this</span>.thread.start();<br />    }<br /> }</div> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br /> 这里可能存在的陷阱是如果此类被继承,那么启动的线程可能无法正确读取子类的初始化操作?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">因此一个简单的原则是,禁止在构造函数中启动线程,可以考虑但是提供一个方法来启动线程。如果非要这么做,最好将类设置为final,禁止继承?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">丢失通知的问?/h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><a href="//www.hncyb.com/xylz/archive/2011/09/05/326988.html" rel="nofollow" style="text-decoration: none; ">这篇文章</a>里面提到过notify丢失通知的问题?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">对于wait/notify/notifyAll以及await/singal/singalAll,如果不确定到底是否能够正确的收到消息,担心丢失通知,简单一点就是总是通知所有?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">如果担心只收到一次消息,使用循环一直监听是不错的选择?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">非常主用性能的系统,可能就需要区分到底是通知单个还是通知所有的挂起者?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2 class="sqkw">线程?/h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">并不是线程数越多越好,在下一篇文章里面会具体了解下性能和可伸缩性?简单的说,线程数多少没有一个固定的结论,受限于CPU的内核数,IO的性能以及依赖的服务等等。因此选择一个合适的线程数有助于提高吞吐量?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">对于CPU密集型应用,线程数和CPU的内核数一致有助于提高吞吐量,所有CPU都很繁忙,效率就很高?对于IO密集型应用,线程数受限于IO的性能,某些时候单线程可能比多线程效率更高。但通常情况下适当提高线程数,有利于提高网络IO的效率,因为我们总是认为网络IO的效率比较低?/p> <p style="margin-top: 1.33em; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">对于线程池而言,选择合适的线程数以及任务队列是提高线程池效率的手段?br /> </p> <div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000FF; ">public</span> ThreadPoolExecutor(<br />     <span style="color: #0000FF; ">int</span> corePoolSize,<br />     <span style="color: #0000FF; ">int</span> maximumPoolSize,<br />     <span style="color: #0000FF; ">long</span> keepAliveTime,<br />     TimeUnit unit,<br />     BlockingQueue<Runnable> workQueue,<br />     ThreadFactory threadFactory,<br />     RejectedExecutionHandler handler)</div> <p> </p> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "><br /> 对于线程池来说,如果任务总是有积压,那么可以适当提高corePoolSize大小;如果机器负载较低,那么可以适当提高maximumPoolSize的大小;任务队列不长的情况下减小keepAliveTime的时间有助于降低负载;另外任务队列的长度以及任务队列?a href="//www.hncyb.com/xylz/archive/2011/01/18/343183.html" rel="nofollow" style="text-decoration: none; ">拒绝策略</a>也会对任务的处理有一些影响?/p> <p> </p> <div id="index"> <div id="previous"><a href="//www.hncyb.com/xylz/archive/2011/12/29/367480.html">并发总结 part 2 常见的并发场?/a> </div> <div id="center" align="center"><a href="//www.hncyb.com/xylz/archive/2010/07/08/325587.html"><strong class="sqkw">?nbsp;  ?/strong></a> </div> <div id="next"><a href="//www.hncyb.com/xylz/archive/2011/12/31/367641.html">并发总结 part 4 性能与伸缩?/a> </div> </div><img src ="//www.hncyb.com/xylz/aggbug/367592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2011-12-30 17:25 <a href="//www.hncyb.com/xylz/archive/2011/12/30/367592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入浅出 Java Concurrency (38): 并发总结 part 2 常见的并发场?/title><link>//www.hncyb.com/xylz/archive/2011/12/29/367480.html</link><dc:creator>imxylz</dc:creator><author>imxylz</author><pubDate>Thu, 29 Dec 2011 08:31:00 GMT</pubDate><guid>//www.hncyb.com/xylz/archive/2011/12/29/367480.html</guid><wfw:comment>//www.hncyb.com/xylz/comments/367480.html</wfw:comment><comments>//www.hncyb.com/xylz/archive/2011/12/29/367480.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.hncyb.com/xylz/comments/commentRss/367480.html</wfw:commentRss><trackback:ping>//www.hncyb.com/xylz/services/trackbacks/367480.html</trackback:ping><description><![CDATA[     摘要: 线程?<br> <br>并发最常见用于线程池,显然使用线程池可以有效的提高吞吐量?<br>最常见、比较复杂一个场景是Web容器的线程池。Web容器使用线程池同步或者异步处理HTTP请求,同时这也可以有效的复用HTTP连接,降低资源申请的开销。通常我们认为HTTP请求时非常昂贵的,并且也是比较耗费资源和性能的,所以线程池在这里就扮演了非常重要的角色?<br>在线程池的章节中非常详细的讨论了线程池的原理和使用,同时也提到了,线程池的配置和参数对性能的影响是巨大的。不尽如此,受限于资源(机器的性能、网络的带宽等等)、依赖的服务,客户端的响应速度等,线程池的威力也不会一直增长。达到了线程池的瓶颈后,性能和吞吐量都会大幅度降低?<br>一直增加机器的性能或者增大线程的个数,并不一定能有效的提高吞吐量。高并发的情况下,机器的负载会大幅提升,这时候机器的稳定性、服务的可靠性都会下降?<br>尽管如此,线程池依然是提高吞吐量的一个有效措施,配合合适的参数能够有效的充分利用资源,提高资源的利用率?nbsp; <a href='//www.hncyb.com/xylz/archive/2011/12/29/367480.html'>阅读全文</a><img src ="//www.hncyb.com/xylz/aggbug/367480.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.hncyb.com/xylz/" target="_blank">imxylz</a> 2011-12-29 16:31 <a href="//www.hncyb.com/xylz/archive/2011/12/29/367480.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入浅出 Java Concurrency (37): 并发总结 part 1 死锁与活跃度 - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/12/29/365149.htmlimxylzimxylzThu, 29 Dec 2011 06:04:00 GMT//www.hncyb.com/xylz/archive/2011/12/29/365149.html//www.hncyb.com/xylz/comments/365149.html//www.hncyb.com/xylz/archive/2011/12/29/365149.html#Feedback2//www.hncyb.com/xylz/comments/commentRss/365149.html//www.hncyb.com/xylz/services/trackbacks/365149.html
    前面谈了很多并发的特性和工具,但是大部分都是和锁有关的。我们使用锁来保证线程安全,但是这也会引起一些问题?
    锁顺序死?lock-ordering deadlock):多个线程试图通过不同的顺序获得多个相同的资源,则发生的循环锁依赖现象?
    动态的锁顺序死锁(Dynamic Lock Order Deadlocks):多个线程通过传递不同的锁造成的锁顺序死锁问题?
    资源死锁(Resource Deadlocks):线程间相互等待对方持有的锁,并且谁都不会释放自己持有的锁发生的死锁。也就是说当现场持有和等待的目标成为资源,就有可能发生此死锁。这和锁顺序死锁不一样的地方是,竞争的资源之间并没有严格先后顺序,仅仅是相互依赖而已?nbsp; 阅读全文

    imxylz 2011-12-29 14:04 发表评论
    ]]>
    编程语言大战 - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/12/06/365658.htmlimxylzimxylzTue, 06 Dec 2011 03:25:00 GMT//www.hncyb.com/xylz/archive/2011/12/06/365658.html//www.hncyb.com/xylz/comments/365658.html//www.hncyb.com/xylz/archive/2011/12/06/365658.html#Feedback8//www.hncyb.com/xylz/comments/commentRss/365658.html//www.hncyb.com/xylz/services/trackbacks/365658.html


    非常令人吃惊的是C++语言依然不够坚挺,由于Windows 7/Windows 8的发力,C#很快就会抢占C++的市场,估计很快就会将C++从前三名中挤下去?



    iPhone/iPad的热销让Object C继续火热,前十的位置还是可以持续很久的,这一点毋庸置疑。移动设备开发的高端人才现在是高薪难求,如果有时间我也要继续关注下?nbsp; 阅读全文

    imxylz 2011-12-06 11:25 发表评论
    ]]>
    处理Zookeeper的session过期问题 - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/12/05/365578.htmlimxylzimxylzMon, 05 Dec 2011 05:57:00 GMT//www.hncyb.com/xylz/archive/2011/12/05/365578.html//www.hncyb.com/xylz/comments/365578.html//www.hncyb.com/xylz/archive/2011/12/05/365578.html#Feedback8//www.hncyb.com/xylz/comments/commentRss/365578.html//www.hncyb.com/xylz/services/trackbacks/365578.htmlSession失效问题

    通常客户端主动关闭连接认为是一次session失效。另外也有可能因为其它未知原因,例如网络超时导致的session失效问题。在服务端看来,无法区分session失效是何种情况,一次一旦发生session失效,一定时间后就会将session持有的所有watcher以及瞬时节点删除?
    而对于Zookeeper客户端而言,一旦发生失效不知道是否该重连,这涉及到watcher和瞬时节点问题,因此Zookeeper客户端认为,一旦发生了seesion失效,那么就认为客户端死掉了。从而所有操作都不能够进行。参?How should I handle SESSION  阅读全文

    imxylz 2011-12-05 13:57 发表评论
    ]]>
    Redis 2.2.x 升级?.4.x - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/11/21/364457.htmlimxylzimxylzMon, 21 Nov 2011 08:48:00 GMT//www.hncyb.com/xylz/archive/2011/11/21/364457.html//www.hncyb.com/xylz/comments/364457.html//www.hncyb.com/xylz/archive/2011/11/21/364457.html#Feedback1//www.hncyb.com/xylz/comments/commentRss/364457.html//www.hncyb.com/xylz/services/trackbacks/364457.html

    有人说Redis的作者是一个勤奋的人,深表同意?


    本来升级是为了增加批量操作从而提高性能,没想到内存占用节省了很多?

    对于32位的操作系统而言,节省内?2%,对?4位操作系统而言节省73%。非常可观?nbsp; 阅读全文

    imxylz 2011-11-21 16:48 发表评论
    ]]>
    兑现 - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/10/10/360915.htmlimxylzimxylzMon, 10 Oct 2011 14:44:00 GMT//www.hncyb.com/xylz/archive/2011/10/10/360915.html//www.hncyb.com/xylz/comments/360915.html//www.hncyb.com/xylz/archive/2011/10/10/360915.html#Feedback3//www.hncyb.com/xylz/comments/commentRss/360915.html//www.hncyb.com/xylz/services/trackbacks/360915.html

    我承认写技术博客是一件特别辛苦和痛苦的事情?/p>


    写一篇技术博客需要大量的技术储备,同时自动亲自动手去实践,证实想表示的,发现要回避的问题,还需要将自己体验的过程记录下来,以便后来人能够避免类似的问题?/p>


    而这一切显然不是写一篇杂记或者转载一篇文章那么容易?/p>


    两年前写一个技术专题,断断续续写了两年,到今天依然没有完成。每次总是希望自己能够很认真、很努力的完成,甚至都有答应网友尽快完成的冲动。可是真正开始时才发现我的注意力明显没有当初那么集中了?/p>


    而我现在更喜欢更新那种Wiki式的技术判断,作为点滴的积累。没有压力,没有负担,随心随意?/p>


    也许需要更多的兴趣和毅力才能坚持下去,不管怎么说,今年还是希望能够有更多的技术文章出来,两年前的承诺也应该勇敢的兑现?/p>



    imxylz 2011-10-10 22:44 发表评论
    ]]>Ganglia安装指南 (基于CentOS 5.6) - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/07/21/354744.htmlimxylzimxylzWed, 20 Jul 2011 16:34:00 GMT//www.hncyb.com/xylz/archive/2011/07/21/354744.html//www.hncyb.com/xylz/comments/354744.html//www.hncyb.com/xylz/archive/2011/07/21/354744.html#Feedback7//www.hncyb.com/xylz/comments/commentRss/354744.html//www.hncyb.com/xylz/services/trackbacks/354744.html

    Ganglia安装指南 (基于CentOS 5.6)

    安装依赖

    rpm -ivh //mirrors.sohu.com/centos/5/os/x86_64/CentOS/zlib-devel-1.2.3-3.x86_64.rpm
    rpm -ivh //mirrors.sohu.com/centos/5/os/x86_64/CentOS/freetype-devel-2.2.1-28.el5_5.1.x86_64.rpm
    rpm -ivh //mirrors.sohu.com/centos/5/os/x86_64/CentOS/libart_lgpl-devel-2.3.17-4.x86_64.rpm
    rpm -ivh //mirrors.sohu.com/centos/5/os/x86_64/CentOS/libpng-devel-1.2.10-7.1.el5_5.3.x86_64.rpm
    

    如果上述安装失败,可能需要安装以下库依赖

    yum install zlib freetype libart_lgpl libpng
    

    安装rrdtools

    //oss.oetiker.ch/rrdtool/pub/rrdtool-1.2.27.tar.gz
    tar zxvf rrdtool-1.2.27.tar
    cd rrdtool-1.2.27
    ./configure --prefix=/usr/local/rrdtool
    make
    make install
    

    执行下命令,看是否安装成?/p>

    /usr/local/rrdtool/bin/rrdtool
    

    安装expat依赖

    //downloads.sourceforge.net/project/expat/expat/2.0.1/expat-2.0.1.tar.gz?use_mirror=cdnetworks-kr-2
    tar zxvf expat-2.0.1.tar.gz
    ./configure --prefix=/usr/local/expat
    make
    make install
    

    对于64位操作系统,需要手动的拷贝下动态链接库到lib64?/p>

    mkdir /usr/local/expat/lib64
    cp -a /usr/local/expat/lib/* /usr/local/expat/lib64/
    

    安装apr以及apr-util

    //labs.renren.com/apache-mirror/apr/apr-1.4.5.tar.gz
    tar xvjf apr-1.3.2.tar.bz2
    ./configure --prefix=/usr/local/apr
    make
    make install
    
    //labs.renren.com/apache-mirror/apr/apr-util-1.3.12.tar.gz
    tar xvjf apr-util-1.3.2.tar.bz2
    ./configure --with-apr=/usr/local/apr --with-expat=/usr/local/expat
    make
    make install
    

    同样64位机器需要拷贝动态链接库

    /bin/cp -f /usr/local/apr/include/apr-1/* /usr/local/apr/include/
    mkdir -p /usr/local/apr/lib64
    /bin/cp -a -f /usr/local/apr/lib/* /usr/local/apr/lib64/
    

    安装confuse

    //download.savannah.gnu.org/releases/confuse/confuse-2.7.tar.gz
    tar zxvf confuse-2.6.tar.gz
    ./configure CFLAGS=-fPIC --disable-nls --prefix=/usr/local/confuse
    make
    make install
    

    拷贝动态链接库

    mkdir -p /usr/local/confuse/lib64
    /bin/cp -a -f /usr/local/confuse/lib/* /usr/local/confuse/lib64/
    

    安装ganglia

    现在才是安装ganglia的开始,如果提示需要pcre的话,安装下 yum install pcre 下载ganglia-3.2.0,解压,安装

    ./configure --prefix=/usr/local/ganglia --with-librrd=/usr/local/rrdtool --with-libapr=/usr/local/apr --with-libexpat=/usr/local/expat \
    --with-libconfuse=/usr/local/confuse --with-gmetad --enable-gexec --enable-status --sysconfdir=/etc/ganglia
    make
    make install
    

    服务端配?/h2>

    创建rrdtool数据目录,看$ganglia-3.2.0/web/conf.php里面的gmetad_root变量,并根据apache的运行用户创建权限,例如apache运行于apache用户??/p>

    mkdir -p /var/lib/ganglia/rrds
    mkdir -p /var/lib/ganglia/dwoo
    chown -R apache;apache /var/lib/ganglia
    

    配置一个数据源,修?etc/ganglia/gmetad.conf文件,同时将运行用户设置为rrdtool的目录权限用户,例如apache用户

    data_source "suc" localhost
    setuid_username "apache"
    

    其中suc是数据源的名称,客户端分组会依赖此名称,后面会提到?添加自启动脚?/p>

    /bin/cp -f gmetad/gmetad.init /etc/init.d/gmetad
    /bin/cp -f /usr/local/ganglia/sbin/gmetad /usr/sbin/gmetad
    chkconfig -add gmetad
    

    启动gmetad服务

    service gmetad start
    

    看见Starting GANGLIA gmetad: [ OK ]就代表运行正常了?/p>

    客户端配置(gmond节点?/h2>

    本机安装如下?/p>

    /bin/cp -f gmond/gmond.init /etc/init.d/gmond
    /bin/cp -f /usr/local/ganglia/sbin/gmond/usr/sbin/gmond
    chkconfig -add gmond
    gmond --default_config > /etc/ganglia/gmond.conf
    

    对于生成的默认配置文件需要做适当的修?/p>

    cluster {
    name="suc"
    owner="apache"
    latlong="unspecified"
    url="unspecified"
    }
    

    其中name是将要在服务端进行的分组,是服务端的数据源。接下来开启服?/p>

    service gmond start
    

    看见Starting GANGLIA gmetad: [ OK ]代表启动成功。如果有失败,可以讲gmond.conf中的debug?改为100,看更多的日志,然后进行排查?/p>

    globals {
    daemonize = yes
    setuid = yes
    user = nobody
    debug_level = 100
    }
    

    非本机客户端配置需要安装服务端安装一样进行配置,运行,非常麻烦,这里使用本机安装好的文件进行安装?使用下面的脚本进行安装deploy-ganglia.sh

    i=$1
    scp /usr/sbin/gmond $i:/usr/sbin/gmond
    ssh $i mkdir -p /etc/ganglia/
    ssh $i mkdir -p /usr/local/ganglia/lib64
    ssh $i mkdir -p /usr/local/expat/lib
    scp /etc/ganglia/gmond.conf $i:/etc/ganglia/
    scp /etc/init.d/gmond $i:/etc/init.d/
    scp -r /usr/local/ganglia/lib64/* $i:/usr/local/ganglia/lib64/
    scp /usr/local/expat/lib/libexpat.so.1 $i:/usr/local/expat/lib/libexpat.so.1
    scp /usr/lib64/libapr-1.so.0 $i:/usr/lib64/
    

    实际上就是将本机安装?编译?的动态链接库拷贝到其它机器上,使用如下命令拷贝即?/p>

    sh deploy-ganglia.sh 10.1.11.2
    

    服务端的WEB配置

    PHP程序需要依赖Apache来运行,因此需要安装如下依?/p>

    yum install php-common php-cli php php-gd httpd
    

    安装web程序,这里假定apache的root路径?var/www/html下面?/p>

    mkdir /var/www/html/ganglia
    cp -a -f ganglia-3.2.0/web/* /var/www/html/ganglia
    

    禁用SELinux setenforce 0 修改rrdtool的路径,文件/var/www/html/ganglia/conf.php中的RRDTOOL

    define("RRDTOOL", "/usr/local/rrdtool/bin/rrdtool");
    

    重启httpd服务器即可看到效?nbsp;service httpd restart

    更多参?//www.imxylz.info/wiki/Ganglia/Ganglia


    imxylz 2011-07-21 00:34 发表评论
    ]]>
    深入浅出 Java Concurrency (36): 线程?part 9 并发操作异常体系 - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/07/12/354206.htmlimxylzimxylzTue, 12 Jul 2011 15:15:00 GMT//www.hncyb.com/xylz/archive/2011/07/12/354206.html//www.hncyb.com/xylz/comments/354206.html//www.hncyb.com/xylz/archive/2011/07/12/354206.html#Feedback3//www.hncyb.com/xylz/comments/commentRss/354206.html//www.hncyb.com/xylz/services/trackbacks/354206.html并发包引入的工具类很多方法都会抛出一定的异常,这些异常描述了任务在线程池中执行时发生的例外情况,而通常这些例外需要应用程序进行捕捉和处理?/p>

    例如在Future接口中有如下一个API?/p>

     

    java.util.concurrent.Future.get(long, TimeUnit) throws InterruptedException, ExecutionException, TimeoutException;

     

    ?a href="//www.hncyb.com/xylz/archive/2011/02/13/344207.html" target="_blank">前面的章?/a>中描述了Future类的具体实现原理。这里不再讨论,但是比较好奇的抛出的三个异常?/p>

    这里有一篇文章(Java 理论与实? 处理 InterruptedException)描述了InterruptedException的来源和处理方式。简单的说就是线程在执行的过程中被自己或者别人中断了。这时候为了响应中断就需要处理当前的异常?/p>

    对于java.lang.Thread而言,InterruptedException也是一个很诡异的问题?/p>

    中断一个线程Thread.interrupt()时会触发下面一种情况:

    如果线程在调?Object 类的 wait()、wait(long) ?wait(long, int) 方法,或者该类的 join()、join(long)、join(long, int)、sleep(long) ?sleep(long, int) 方法过程中受阻,则其中断状态将被清除,它还将收到一?InterruptedException?/p>

    检测一个线程的中断状态描述是这样的Thread.interrupted()?/strong>

    测试当前线程是否已经中断。线程的中断状?/em> 由该方法清除。换句话说,如果连续两次调用该方法,则第二次调用将返?false(在第一次调用已清除了其中断状态之后,且第二次调用检验完中断状态前,当前线程再次中断的情况除外)?nbsp;

    也就是说如果检测到一个线程已经被中断了,那么线程的使用方(挂起、等待或者正在执行)都将应该得到一个中断异常,同时将会清除异常中断状态?/p>

     

    V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException {
        
    if (!tryAcquireSharedNanos(0, nanosTimeout))
            
    throw new TimeoutException();
        
    if (getState() == CANCELLED)
            
    throw new CancellationException();
        
    if (exception != null)
            
    throw new ExecutionException(exception);
        
    return result;
    }

     

    上面获取任务结果的方法实现中,将在获取锁的过程中得到一个中断异常。代码java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(int, long)描述了这种情况:

        public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout) throws InterruptedException {
        
    if (Thread.interrupted())
            
    throw new InterruptedException();
        
    return tryAcquireShared(arg) >= 0 ||
            doAcquireSharedNanos(arg, nanosTimeout);
        }

     


    这里在获取锁的时候检测线程中断情况,如果被中断则清除中断位,同时抛出一个中断异常。为什么如此做?因为我们的线程在线程池中是被重复执行的,所以一旦线程被中断后并不会退出线程,而是设置中断位,等候任务队列自己处理线程,从而达到线程被重复利用的目的。有兴趣的可以参考代码java.util.concurrent.ThreadPoolExecutor.Worker.runTask(Runnable)。这里在关闭线程池时就会导致中断所有线程?/p>

    除了InterruptedException 异常我们还发现了一个全新的异常java.util.concurrent.TimeoutException,此异常是用来描述任务执行时间超过了期望等待时间,也许是一直没有获取到锁,也许是还没有执行完成?/p>

    在innerGet代码片段中我们看到,如果线程在指定的时间无法获取到锁,那么就会得到一个超时异常。这个很好理解,比如如果执行一个非常耗时的网络任务,我们不希望任务一直等待从而占用大量的资源,可能在一定时间后就会希望取消此操作。此时超时异常很好的描述了这种需求?/p>

    与此同时,如果取消了一个任务,那么再次从任务中获取执行结果,那么将会得到一个任务被取消的异常java.util.concurrent.CancellationException?/p>

    除了上述异常外,还将得到一个java.util.concurrent.ExecutionException异常?/p>

    这是因为我们的提交的任务java.util.concurrent.Callable在call()方法中允许抛出任何异常,另外常规的线程执行也可能抛出一个RuntimeException,所以这里简单包装了下所有异常,当作执行过程中发生的异常ExecutionException抛出?/p>

    以上就是整个异常体系,所有并发操作的异常都可以归结于上述几类?/p>

    很多情况下处理时间长度都是用java.util.concurrent.TimeUnit,这是一个枚举类型,用来描述时间长度。其中内置了一些长度的单位。其中包括纳秒、微秒、毫秒、秒、分、时、天。例如超时操?秒,可以使用

    Future.get(5,TimeUnit.SECONDS) 或?Future.get(5000L,TimeUnit.MILLISECONDS)

    当然一种单位的时间转换成另一种单位的时间也是非常方便的。另外还有线程的sleep/join以及对象的wait操作的便捷操作?/p>

     



    imxylz 2011-07-12 23:15 发表评论
    ]]>
    享受热部署的好处 - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/06/17/352476.htmlimxylzimxylzFri, 17 Jun 2011 01:25:00 GMT//www.hncyb.com/xylz/archive/2011/06/17/352476.html//www.hncyb.com/xylz/comments/352476.html//www.hncyb.com/xylz/archive/2011/06/17/352476.html#Feedback3//www.hncyb.com/xylz/comments/commentRss/352476.html//www.hncyb.com/xylz/services/trackbacks/352476.html

    你还在为频繁部署服务器而烦恼么?br />
    亲,试试jrebel吧。更多jrebel的介绍参考这?a target="_blank" style="color: #4d87c1; text-decoration: none; font-family: arial; font-weight: bold; font-size: 1.1em; ">//www.zeroturnaround.com/jrebel/?/p>

    啊?免费版只能使?0天?花钱?十个人的团队使用一年的企业版License?span style="font-family: 'Comic Sans MS'; font-size: 18pt; ">2891$!你没看错,是真真正正的美帝国的钱!

    好吧,我等穷人使用不起,只好“自己动手/丰足食”?/p>

    这里提供了一个完整功能的企业版,免费大甩送了,有木有!!!

     

    怎么使用,最简单方?在resin的启动文件,例如httpd.sh中增加:

    Resin 3.1+版本?/p>

    exec $JAVA_EXE -javaagent:/opt/apps/resin/jrebel4.0-crack.jar -jar ${RESIN_HOME}/lib/resin.jar $*

    Resin 3.0-版本?/p>

    args=”-J-javaagent:/opt/apps/resin/jrebel4.0-crack.jar

    Tomcat?Jetty? Jboss? WebLogic? WebSphere? Maven? Eclipse? And More?

    OK,参考这里文?吧?a target="_blank" style="color: #4d87c1; text-decoration: none; font-family: arial; font-weight: bold; font-size: 1.1em; ">//www.zeroturnaround.com/reference-manual/

    亲,不要钱的,试试吧?/p>

    有木有更简单,更NB的热部署秘籍啊?

    有的,亲?/p>

    如果你的Linux x86 (x86_64位目前没?的glibc?.4+版本,试?a target="_blank" style="color: #4d87c1; text-decoration: none; font-family: arial; font-weight: bold; font-size: 1.1em; ">dcevm吧!Windows 32/64位同样有相应的版本啊?/p>

    imxylz 2011-06-17 09:25 发表评论
    ]]>
    Crack JRebel 4.0,无需重启JVM,热部署解决方案 - 3d走势图综合版//www.hncyb.com/xylz/archive/2011/06/12/352109.htmlimxylzimxylzSat, 11 Jun 2011 16:24:00 GMT//www.hncyb.com/xylz/archive/2011/06/12/352109.html//www.hncyb.com/xylz/comments/352109.html//www.hncyb.com/xylz/archive/2011/06/12/352109.html#Feedback36//www.hncyb.com/xylz/comments/commentRss/352109.html//www.hncyb.com/xylz/services/trackbacks/352109.html//dl.dropbox.com/u/22951342/jrebel.jar  www.zeroturnaround.com最近又接触到一点WEB应用,想到Resin服务器重启需要花费比较多的时间(Spring将WEB服务搞得越来越复杂,越来越臃肿了),所以又想到?8年那时候用JavaRebel了。一段时间不用人家居然改名为JavaRebel了?br />如果不熟悉的可以搜索下JRebel/JavaRebel,这里是官方网站?div style="display: inline-block; ">
    www.zeroturnaround.com?br />最近刚发布?.0版本,功能更强大,配置也更加简单了。价格不菲?br />官方提供30天试用版,可以先体验下再决定是否购买?br />
    看到里面的代码混淆让我很崩溃,没有深入研究混淆后的运行机制。比如下面居然有两个名称相同,参数相同,但是返回值不同的静态方法,不知是如何执行的?br />public static void a(String s)?public static String a(String),以?br />private static void c()和private static String c()?br />猜测是在运行的时候自己进行JVM指令的执行。这样的代码反编译后都不知道怎么写回去,想到崩溃,因为两个方法居然都有地方调用了?br />


    zhangthe9 提供了一?.0的破解版,我很好奇,咨询了下,居然还是以前的RSA签名算法?/div>
    好吧,翻?8年写的JavaRebel 2.0-M1的破解程序,重新生成一个license文件,修改公钥,替换license文件,居然运行正常。这么多年了,签名算法和步骤居然一点都没变,嗯,人家真执着?br />当然是无限制版,所有功能可用,也没有时间限制?br />

    #############################################################

     JRebel 
    4.0 (201105311152)
       with Enterprise Add
    -On! (see http://jrebel.com/enterprise)
     (c) Copyright ZeroTurnaround OU, Estonia, Tartu.

     Over the last 
    1 days JRebel prevented 
     at least 
    0 redeploys/restarts saving you about 0 hours.

     This product is licensed to www.imxylz.info
     
    for unlimited number of developer seats on site.
     
    == Cracked by imxylz (imxylz#gmail.com) from JavaRebel 2.0-M1, 2008 ==

    #############################################################

    伟大领袖毛主席,指引我们向前进!
    jrebel cracked by imxylz
    伟大领袖毛主席,指引我们向前进!
    jrebel cracked by imxylz
    JRebel: Reloading class 'ReloadClass'.change 
    伟大领袖毛主席,指引我们向前进!
    class!

    破解思路很简单,替换公钥,使用自己私钥生成签名License文件?br />如果想屏蔽版本更新提示,有以下几种思路?br />?)修改调用更新坚持的类(难道有点大,因为混淆比较严重,不容易反编译)
    ?)修改更新服务器的地址,将//update.zeroturnaround.com/jrebel/地址修改,可以使用二进制工具直接修改字符串,比如我就将update改为updatt,无法解析域名就不能获取最新版本了?br />?)增?Drebel.disable_update=true参数即可。(这种方法最简单)?br />
    当然了,为了“保护知识产权”,不会将破解文件放出来,有需求的可以留言联系。(所谓的“计算机条?#8221;是允许为了学习、研究而进行相关逆向工程的,哈哈)?/strike>

    好吧,架不住国人的热情,这里是下载地址,需要翻X,你懂得?div style="display: inline-block; ">
    //dl.dropbox.com/u/22951342/jrebel.jar  

    [关键字: JRebel, JavaRebel, JRebel Crack, JRebel License, JavaRebel License]


    ]]>
  • δȫԤ̨غ 2019-03-18
  • ձԱҡѵøӼǿ 2019-03-18
  • ɹųԭгνܼͼ 2019-03-15
  • ȸΪЩԭѡɽڷ׸˹ 2019-03-14
  • ¹СӣëǮҲҪ˵[ͼ] 2019-03-14