??xml version="1.0" encoding="utf-8" standalone="yes"?>BlogJava-xylz,imxylzhttp://www.dentisthealthcenter.com/xylz/x后端架构、中间g、分布式和ƈ发编E?/description>zh-cnThu, 07 Dec 2023 16:25:53 GMTThu, 07 Dec 2023 16:25:53 GMT60世界邦旅行网(北京)招聘Java高/资深工程师前端工E师/Ud开发工E师{_20150616更新http://www.dentisthealthcenter.com/xylz/archive/2013/11/05/406019.htmlimxylzimxylzTue, 05 Nov 2013 09:01:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2013/11/05/406019.htmlhttp://www.dentisthealthcenter.com/xylz/comments/406019.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2013/11/05/406019.html#Feedback15http://www.dentisthealthcenter.com/xylz/comments/commentRss/406019.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/406019.html
  • 工作地点Q北?/li>
  • 世界邦旅行网是一个新型出境自助旅行社区和电子商务开攑^収ͼ以提供“个性化行程定制服务Q高性h比、高质量境外自助游”ؓ目标?/li>
  • 我们的网站:http://www.shijiebang.com
  • 关于我们Q?a >http://www.shijiebang.com/about/us/
  • B轮数?/li>
  • 招聘职位
    • Java 高/资深工程?/li>
    • PHP 工程?/li>
    • 试工程?/li>
    • 前端工程?/li>
    • Ud开发工E师(Android/iOS)
    • 其它市场、推qѝ运营、品、设计等人才
  • 待遇
    • 与互联网公司看齐+期权 Qh值几何问自己Q?/li>
  • 特别说明

    • 有github帐号, stackoverflow 有A献分Z
    • 不会qiang的不投递简?/li>
    • 管融资有点钱,但依然条件艰苦(创业何其艎ͼ
    • 必须自认明(即别h认ؓ自己不聪明,要有q䆾霸气Q?/li>
    • Ҏ游或者旅行有兴趣
    • 一个能够快速自我成长的环境Q如果不能徏议立卛_L他处
    • 无意义的技术、工兯求没?/li>
  • 最后的最?/p>

    • 历写各种_N的Q徏议不用考虑
  • 联系方式
    • imxylz##gmail.com
  • 更新旉Q?2015/06/16



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

    imxylz 2013-10-08 17:17 发表评论
    ]]>
    Octopress加速Google字体渲染http://www.dentisthealthcenter.com/xylz/archive/2013/09/22/move-google-fonts-to-local-server.htmlimxylzimxylzSun, 22 Sep 2013 13:42:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2013/09/22/move-google-fonts-to-local-server.htmlhttp://www.dentisthealthcenter.com/xylz/comments/404298.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2013/09/22/move-google-fonts-to-local-server.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/404298.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/404298.html阅读全文

    imxylz 2013-09-22 21:42 发表评论
    ]]>
    JRebel 6.0.0 Crack (20141216更新)http://www.dentisthealthcenter.com/xylz/archive/2013/09/15/404098.htmlimxylzimxylzSun, 15 Sep 2013 15:24:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2013/09/15/404098.html阅读全文

    imxylz 2013-09-15 23:24 发表评论
    ]]>
    甌SSL证书及Nginx支持HTTPShttp://www.dentisthealthcenter.com/xylz/archive/2013/09/11/403965.htmlimxylzimxylzWed, 11 Sep 2013 13:58:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2013/09/11/403965.htmlhttp://www.dentisthealthcenter.com/xylz/comments/403965.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2013/09/11/403965.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/403965.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/403965.html阅读全文

    imxylz 2013-09-11 21:58 发表评论
    ]]>
    随机选择集合的子元素集合http://www.dentisthealthcenter.com/xylz/archive/2013/08/17/402978.htmlimxylzimxylzSat, 17 Aug 2013 09:44:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2013/08/17/402978.htmlhttp://www.dentisthealthcenter.com/xylz/comments/402978.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2013/08/17/402978.html#Feedback3http://www.dentisthealthcenter.com/xylz/comments/commentRss/402978.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/402978.html我需要一个从集合N中随机选择M个子元素的算法?当然最好的办法是将集合打ؕ序Q然后从中选择前M个元素即可?Java中现成的API可以使用Q?/div>
    java.util.Collections.shuffle(List<?>)
    此算法非常简单,循环Nơ,每次长度减少1Q随取其中一个元素,然后交换其对U元素?/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)));
    }

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

    考虑到性能以及q发讉KQ多U程Q的需要,我想C一个简单的法Q?/div>
    l定N个元素集合,从中选择M(0<M<=N)个元素的办法是,
    1. 随机选择索引K(0<=K<N), i=0, I子?/li>
    2. 取有效元素N(k-i),N(k+i) 加入未满子集M
    3. i+=1, 重复(2) 直到子集M已满
    4. l止
    q样取出来的元素虽然和原始集序有一定的关系Q但是每个元素在子集里出现的概率相当Q满结果要求?最后生成的法如下Q?/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. U程安全Q原始集合不变)
    3. 子元素出现概率相当(未经数学证明

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



    imxylz 2013-08-17 17:44 发表评论
    ]]>捕获JavaU程池执行Q务抛出的异常http://www.dentisthealthcenter.com/xylz/archive/2013/08/05/402405.htmlimxylzimxylzMon, 05 Aug 2013 08:45:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2013/08/05/402405.htmlhttp://www.dentisthealthcenter.com/xylz/comments/402405.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2013/08/05/402405.html#Feedback6http://www.dentisthealthcenter.com/xylz/comments/commentRss/402405.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/402405.htmlJava中线E执行的d接口java.lang.Runnable 要求不抛出Checked异常Q?/p>
    public interface Runnable {

        
    public abstract void run();
    }

    那么如果 run() Ҏ中抛ZRuntimeExceptionQ将会怎么处理了?

    通常java.lang.Thread对象q行讄一个默认的异常处理ҎQ?/p>

    java.lang.Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler)

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

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

    public interface UncaughtExceptionHandler {

        
    void uncaughtException(Thread t, Throwable e);
    }

    而在U程池中却比较特D。默认情况下Q线E池 java.util.concurrent.ThreadPoolExecutor 会Catch住所有异常, 当Q务执行完?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 异常xjava.lang.Runnable 或?java.util.concurrent.Callable 抛出的异常?/p>

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

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

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

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

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

    解决办法如下Q?/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);
    }

    此办法的关键在于Q事实上 afterExecute q不会L抛出异常 Throwable tQ通过查看源码得知Q异常是装在此时的Future对象中的Q?而此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;
            }
        }
    }

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

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

    当我们获取异步执行的l果Ӟ 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>

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

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

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

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



    imxylz 2013-08-05 16:45 发表评论
    ]]>
    Python 基础文g操作http://www.dentisthealthcenter.com/xylz/archive/2013/02/24/395677.htmlimxylzimxylzSun, 24 Feb 2013 12:55:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2013/02/24/395677.htmlhttp://www.dentisthealthcenter.com/xylz/comments/395677.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2013/02/24/395677.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/395677.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/395677.html

    File - 基础文g操作

    学习一门语aQ我L喜欢从文件开始。文本文件的d操作是我比较在意的基本功能?在这斚wQJava语言功能比较强大Q用到的设计模式也非常多。只是用v来太q繁琐?而Python在这斚w表现非常好,z不失功能,强大不失性能Q通俗不失优雅Q值得U赞?/p>

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

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

    q里有用?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()的参C多,通常需要关注的是mode/encoding/errors/newline{?/p>

    最佛_?/h3>
    (1) d文g必须传入字符~码encoding 
    (2) 用完的流需要关闭,推荐使用with操作
    (3) 换行W尽可能的用UNIX格式(\n)Q尽python可以转换
    (4) 如果可以的话可能的使用utf-8~码来处理非ascii字符Q不要依赖操作系l的~码

    脓?/p>

    多个文g同时操作可用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

    文g对象描述的是一U?#8220;?#8221;操作Q通常支持read()或者write()Ҏ?q里的文件对象是一U概念上?#8220;文g对象”Q除了常见的真是的磁盘文Ӟq可以是 标准输入输出文g(stdin/stdout/stderr)Q内存缓冲区(StringIO,cStringIO)Q?socketQpipes{?/p>

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

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

    Text I/O

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

    read() 是读取文本的最单的Ҏ。返回的是字W串形式的结果(和参数encoding有关Q?/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() 

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

    脓士:

    如果已经d到文件末,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.

    d一行意味着和行l束W有养Iq个有点复杂?/p>

    d多行Q用readlines()Ҏ。这返回一个字W串列表。readlines()也可以限制最多读取多个字符?/p>

    脓士:

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

    例如Q?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)ҎQ?/p>

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

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

    脓士:

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

    Binary I/O

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

    例如Q?/p>

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

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

    • read()q回的值是字节(bytes)
    • readline()q回的值是字节(bytes)Q包括换行符
    • readlines()q回的值是字节(bytes)列表Q包括换行符
    • 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)是将内容d到bytearray b中,q回d的字节数?/li>

    其它文g操作

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

    • file.close() 关闭文g
    • file.fileno() 获取文g描述W(整Ş|
    • file.flush() 对于有缓冲区的写操作Q刷新缓冲区
    • file.tell() q回当前的字节位置
    • file.seek() Ud文g的当前位置
    • file.truncate() 截断文g大小

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

    imxylz 2013-02-24 20:55 发表评论
    ]]>
    Crack JRebel 5.3.1http://www.dentisthealthcenter.com/xylz/archive/2012/12/26/393498.htmlimxylzimxylzWed, 26 Dec 2012 04:02:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/12/26/393498.htmlhttp://www.dentisthealthcenter.com/xylz/comments/393498.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/12/26/393498.html#Feedback31http://www.dentisthealthcenter.com/xylz/comments/commentRss/393498.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/393498.html
    我一直?.1.0版本的jrebelQ是social免费版本的。social版本会在启动时连接jrebel服务器(myrebel)获取licenseQ同时会一些热部v的次数、节U时间、性能{日志提交到q程服务器?br /> 最q中国网l抽风,q接jrebel服务器特别慢Q导致每ơ启动的时候都需?0s以上的时间才能得到服务器的响应(加上自动更新)。最Z个技术控Q很昄Q我不能忍受q种行ؓ?br />
    只好研究如何破解它?br /> ?.0开始jrebel的؜淆机制做得非常棒Q基本上无法q行反编译修改了。好在jrebel比较厚道Q一直兼Ҏ版本的license机Ӟd?008q写的破解工E,利解决?.1.0版本?br /> 然后下蝲最新的5.1.2Q?0121217Q版本,试了下居然没有成功。太囧了。这是一个小版本Qؓ何改动如此大Q?br />
    打开debug日志后发玎ͼҎ没有加载jrebel.jar里面的License文g。反~译源码看了下,果然Q从5.1.2版本开始不再加载jrebel.jar里面的license文g了,该从用户ȝ录,jrebel安装目录{获取license文g。这样就没法通过一个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版本Q所以可以放Z个低版本Q我一直用)5.1.2?.1.3暂时不去解决了?br />


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

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

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

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

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

     

    关键词: 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入门http://www.dentisthealthcenter.com/xylz/archive/2012/09/25/388519.htmlimxylzimxylzTue, 25 Sep 2012 08:34:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/09/25/388519.htmlhttp://www.dentisthealthcenter.com/xylz/comments/388519.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/09/25/388519.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/388519.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/388519.htmlSQLite3 C语言API入门

    下蝲SQLite3

    我们下蝲sqlite源码?/a>Q只需要其中的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>

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

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

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

     

    打开数据库除了这UŞ式意外,q有sqlite3_open、sqlite3_open16、sqlite3_open_v2几种形式Q基本上cM?/p>

    大部分sql操作都可以通过sqlite3_exec来完成,它的API形式如下Q?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 */
    );

     

    各个参数的意义ؓQ?/p>

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

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

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

     

    每一个参数意义如下:

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

    通常情况下callback在select操作中会使用刎ͼ其是处理每一行记录数。返回的l果每一行记录都会调用下“回调函数”?如果回调函数q回了非0Q那么sqlite3_exec返回SQLITE_ABORTQƈ且之后的回调函数也不会执行,同时未执行的子查询也不会l箋执行?/p>

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

    通常情况下sqlite3_execq回SQLITE_OK=0的结果,?l果可以通过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>

    Z防止垃圾数据Q我们在加蝲数据库的时候删除表操作?/p>

    单的删除操作可以直接使用sqlite3_exec卛_。这里不需要回调函C及回调函数的参数?当然需要可以关注sqlite3_execq回的结果是否ؓ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);

     

    插入数据

    插入W一条数?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");

     

    q回值ret为SQLITE_OKx作成功?/p>

    插入多条数据Qƈ删除数据

        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");
    插入多条数据Q简单的使用sqlite3_execq行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);
    预编译操作比较麻烦的Q完整的预编译操作的程是:
    1. 通过sqlite3_prepare_v2()创徏一个sqlite3_stmt对象
    2. 通过sqlite3_bind_*()l定预编译字D늚?/li>
    3. 通过sqlite3_step()执行SQL语句
    4. 通过sqlite3_reset()重置预编译语句,重复操作2多次
    5. 通过sqlite3_finalize()销毁资?/li>

    sqlite3_prepare_v2()有个多种cM的Ş式,完整的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 */
    );

     

    各个参数的定义ؓQ?/p>

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


    l定参数sqlite3_bind_*有多UŞ式,分别对应不同的数据类?

    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语句中可以包含如下几UŞ式:

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

    NNN代表数字QVVV代表字符丌Ӏ?/p>

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

    查询操作

    回调函数的解释参考最上面的描q?首先声明一个回调函数?/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);
        }

     

    现在定义回调函数Q只是简单的输出字段倹{?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语法Q?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);

     

    其中Q?/p>

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

    ׃sqlite3_get_table是sqlite3_exec的包装,因此q回的结果和sqlite3_execcM?/p>

    pazResult是一?pnRow+1)*pnColumnl果集的字符串数l,其中前pnColumn个结果是字段的名Uͼ后pnRow行记录是真实的字D|如果某个字段为空Q则对应gؓNULL?/p>

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

    更新操作

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

    当然了,我们也可以用预~译Ҏq行更新操作?/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));
    }

    ȝ

    q里我们接触了SQLITE3?3个APIQ?/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函数Q?a rel="nofollow" style="text-decoration: none; ">http://www.sqlite.org/c3ref/funclist.htmlQ?/a>

    但最_的API函数大概?个:

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

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

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

    因此掌握hq是比较Ҏ的?br />
    完整的源码地址Q?
    https://gist.github.com/3780669



    imxylz 2012-09-25 16:34 发表评论
    ]]>
    分布式消息系lJafka 发布1.2.0版本http://www.dentisthealthcenter.com/xylz/archive/2012/06/26/381490.htmlimxylzimxylzTue, 26 Jun 2012 02:51:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/06/26/381490.htmlhttp://www.dentisthealthcenter.com/xylz/comments/381490.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/06/26/381490.html#Feedback2http://www.dentisthealthcenter.com/xylz/comments/commentRss/381490.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/381490.htmlJafka 是一个高性能的分布式消息pȝ。Jafka已经开源,使用github托管Q主地址Q?/span>https://github.com/adyliu/jafka

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

    imxylz 2012-06-26 10:51 发表评论
    ]]>
    Fedora 17 降一把辛酸泪http://www.dentisthealthcenter.com/xylz/archive/2012/06/07/380210.htmlimxylzimxylzThu, 07 Jun 2012 04:13:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/06/07/380210.htmlhttp://www.dentisthealthcenter.com/xylz/comments/380210.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/06/07/380210.html#Feedback9http://www.dentisthealthcenter.com/xylz/comments/commentRss/380210.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/380210.html

    Fedora 17发布Q第二天立马更新了?首先光是更新折腾了很久Qȝ弄好了。结果发C个巨大的问题。gtk2与eclipse不兼宏V?/p>

    不兼容的后果是L报这L错误Q命令行启动eclipseQ?nbsp;eclipse -debug -consolelogQ:

    (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

    表现为打开~辑器后L有很多内Ҏ法显C,昄为空白,必须重新选定或者拖动滚动条才能昄?/p>

    qo人崩溃啊Q!Q?/strong>

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

    好吧Q上|找找。发现有些h也遇C兼容问题。但是没有一个解军_法?/p>

    我的解决q程是这P

    • 更新整个fedora环境Q发布后官方发布了一些紧急修正包Q,未果
    • 重新下蝲最新发行版的eclipseQ未?/li>
    • 重新下蝲最新的试版本eclipseQ未?/li>
    • 下蝲fedora18的gtk2、glibc{强制安装,未果
    • 降gtk2、glibc{到fedora 16Q未?/li>
    • l箋googleQ寻找解x法,依然未果
    • 替换最新发布的二进制swt库,未果
    • 试手动~译swt源码Q未成功

    q样Q折腾了几天Q快要放弃了?/p>

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

    今天早上H然惛_Q公叔R的那台笔记本q是Fedora 16未升U。于是想强制降到swt所有依赖库到Fedora 16看能否解决问题?/p>

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

    yum list

    yum install

    yum erase

    yum --releasever=16 downgrade

    rpm -qa

    rpm -qf

    ldd

    lsof

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

    q个q程l过了长达两个小时的折腾和仿佛。最l终于成功完成了以下依赖的降U?/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>

    ȝ下:

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

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

    imxylz 2012-06-07 12:13 发表评论
    ]]>
    分布式消息系lJafka 发布1.1.0版本http://www.dentisthealthcenter.com/xylz/archive/2012/05/27/379308.htmlimxylzimxylzSun, 27 May 2012 02:53:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/05/27/379308.htmlhttp://www.dentisthealthcenter.com/xylz/comments/379308.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/05/27/379308.html#Feedback1http://www.dentisthealthcenter.com/xylz/comments/commentRss/379308.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/379308.htmlhttps://github.com/adyliu/jafka

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

    服务?/strong>Q?/p>

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

    客户?/strong>Q?/p>


    下蝲地址
    Q?

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

    创徏slice文g

    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

    q接
    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
    q行服务?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

    q接
    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

    q行客户?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 发表评论
    ]]>分布式消息系ljafka快速v?/title><link>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2012/05/11/377938.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/377938.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2012/05/11/377938.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/377938.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/377938.html</trackback:ping><description><![CDATA[     摘要: Jafka 是一个开源的/性能良好的分布式消息pȝ。在上一文章中有所单介l?下面是一简单的入门文。更多详l的文参考wiki? Step 1: 下蝲最新的安装?完整的安装指南在q里?最新的发行版地址在:https://github.com/adyliu/jafka/downloads $wget https://github.com/downloads/adyliu/j...  <a href='http://www.dentisthealthcenter.com/xylz/archive/2012/05/11/377938.html'>阅读全文</a><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/377938.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2012-05-11 18:48 <a href="http://www.dentisthealthcenter.com/xylz/archive/2012/05/11/377938.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jafka - 一个高性能的消息系l?/title><link>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2012/05/10/377759.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/377759.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2012/05/10/377759.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/377759.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/377759.html</trackback:ping><description><![CDATA[<p>Jafka 是一个高性能的分布式消息pȝ。Jafka已经开源,使用github托管Q主地址Q?a target="_blank">https://github.com/adyliu/jafka<br /> </a><br /> Jafka 1.0版本已经发布Q同步到Maven中央仓库?br /> <br /> Jafka是由Apache孵化的Kafka(由LinkedIn捐助lApacheQ克隆而来。Jafka 1.0完整遵@Kafka 0.7的规范,几乎是Kafka的克隆版Q有一些改q和调整Q?br /> Jafka有几个吸引h的特性:<br /> <br /> <ul> <li>消息持久化非常快Q服务端存储消息的开销为O(1)Qƈ且基于文件系l,能够持久化TBU的消息而不损失性能</li> <li>吞吐量很大,在我的单机DELL E6220Q现已经停Q、Fedora 16 x86_64下单CPU内核q行Q用Jafka内置的python客户端,吞吐量能够达?00k/s</li> <li>完全的分布式pȝQbroker、producer、consumer都原生自动支持分布式。自动实现复杂均衡?/li> <li>内核非常,整个pȝQ包括服务端和客LQ只有一?72KB的jar包,内部机制也不复杂Q适合q行内嵌或者二ơ开? 。整个服务端加上依赖lg?.5MB?/li> <li>消息格式以及通信机制非常单,适合q行跨语a开发。目前自带的Python 3.x的客L支持发送消息和接收消息?/li> </ul> 另外Q这里有一个分享的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> <iframe height="426" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/12795614" frameborder="0" width="510" marginwidth="0" scrolling="no"></iframe> <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上的源码Q进行二ơ开发或者按照自己喜Ƣ的方式q行改进。如果有好的Ҏ或者发现bug请友情提醒我?另外Q友情支持淘宝内部用的Kafka克隆?a target="_blank">metaq</a>,内部做了大量的改q和附加lg。如果你需要一个全功能?#8220;复杂”pȝQ可以试试metaq.<img src ="http://www.dentisthealthcenter.com/xylz/aggbug/377759.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2012-05-10 10:08 <a href="http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2012/04/12/372999.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/372999.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2012/04/12/372999.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/372999.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/372999.html</trackback:ping><description><![CDATA[<!--PageText--> <div id="wikitext"> <h1><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> 8.x 模块?/h1> <p><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> 8.x带有一个默认的test环境。我们从q个默认的环境入手? </p> <p class="vspace">首先Q来分析下start.ini里面的配|,q个配置军_启动了哪些模块? </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">利用上节学到的只是,我们先来分析下用C那些模块? </p><pre class="escaped">java -jar start.jar --list-options </pre> <p class="vspace">查找Server,jsp,jmx,resources,websocket,ext,plus,annotationsq些对应的模块有Q? </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">从上一节中我们知道Q这些模块相当于那些组件加入classpath中,jetty在启动时也会装蝲q些模块? </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军_了启动不同的模块Q也是不同的组件和classpathQ。另外,对于start.config里面的不同的OPTION可能有相同的模块依赖? </p> <p class="vspace">默认的test.war启动了如下模块: </p><ul><li>Server: 一个标准的servlet容器 </li><li>jsp: jsp模块 </li><li>jmx: jmx支持 </li><li>resources: 允许?{jetty.home}/resources中读取类资源Q实际上是配|log4j.properties) </li><li>websocket: 支持websocket的例? </li><li>ext: ׃${jetty.home}/lib/ext目录为空Q实际上什么都做。其实此Ҏ是Z装蝲自定义的lg依赖? </li><li>plus: 一些扩展支持,从上面classpath中猜,应该是jndi、java认证以及java mail的组件? </li><li>annotations: java注解以及字节码的支持? </li></ul><div class="vspace"></div><h2>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="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.xml</h3> <p>默认的jetty.xml负责配置讄服务器的参数Q包括绑定的地址、线E池大小以及一些默认的处理?HandlerQ等? </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="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.host" /></Set> <Set name="port"><Property name="<a title="" href="http://www.dentisthealthcenter.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">可以看出默认的线E池大小是最线E?0个,最大线E?00个。绑定在所有网卡的8080端口。其它配|以后再分析? </p> <div class="vspace"></div><h3><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-annotation.xml</h3> <p><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-annotation.xml配置应该是描q支持哪些注解配|方式? </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="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-deploy.xml</h3> <p><a title="" href="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-webapps.xml</h3> <p><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-webapps.xml定义要发布的内容Q通常是要发布应用或者应用的定义。默认是存放?{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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-contexts.xml</h3> <p><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-contexts.xml定义一些预|规则。类g一些拦截器。例如可以讲某些URI rewrite或者静态资源cache配置{? </p> <p class="vspace">q会自动扫描${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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>-testrealm.xml</h3> <p><a title="" href="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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>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" "http://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="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.host" /></Set> <Set name="port"><Property name="<a title="" href="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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文g不存在,也就是不使用start.ini里面的配|? </p> <p class="vspace">手动q行它? </p><pre class="escaped">java -jar start.jar OPTIONS=Server,jsp,jmx,resources,websocket,ext,plus,annotations etc/test.xml </pre> <p class="vspace">q时候的启动和默认启动是一L了? </p> <p class="vspace">q时候就可以讉K了? </p> <div class="vspace"></div><h2><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> Statistics</h2> <p>q一部分Q我们利用学习到的只是来部v一个Jettyl计模块? </p> <div class="vspace"></div><h3>修改讄</h3> <p>连接计数参数打开Q? </p><pre class="escaped"> <Call name="addConnector"> <Arg> <New class="org.eclipse.jetty.server.nio.SelectChannelConnector"> <Set name="host"><Property name="<a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a>.host" /></Set> <Set name="port"><Property name="<a title="" href="http://www.dentisthealthcenter.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>Z不媄响默认的test.war环境Q我们增加一个最单的WAR环境? </p> <p class="vspace">Ҏ前面学到的知识,只需要将war环境攑ֈwebapps目录下即可。可以是一个war包,也可以是一个以.warl尾的目录? </p><pre class="escaped">$tree webapps/demo.war/ webapps/demo.war/ `-- WEB-INF |-- <a title="" href="http://www.dentisthealthcenter.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" "http://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="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://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">说明几点Q? </p><ul><li>Z不和test.war的contextPathhQ这里强制修改ؓ/demo? </li><li>增加一个jetty内置的统计servlet(org.eclipse.jetty.servlet.StatisticsServlet) </li><li>servlet的参数restrictToLocalhost修改为falseQ否则默认情况下只能通过本机讉KQ不能远E访? </li></ul><div class="vspace"></div><h3>q行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">http://127.0.0.1:8080/demo/statistic/ </pre> <p class="vspace">效果如下Q? </p><div><img src="http://dev.imxylz.info/wiki/./wiki/upload/Jetty/statistic1.png" alt="" title="" /></div> <div><img src="http://dev.imxylz.info/wiki/./wiki/upload/Jetty/statistic2.png" alt="" title="" /></div> <p class="vspace">l计l果包含6个部分: </p><ol><li>l计l果攉旉 </li><li>h数详情(当前h数、最大请求数、dh数、请求时间等Q? </li><li>h分发详情Q和hC同的是,q是jetty内部分发h的数量,包括forward/include{) </li><li>响应状态详情(1xx/2xx/3xx/4xx/5xx以及d发送的字节敎ͼ </li><li>q接数详?Q当前连接数、最大连接数、连接持l时间等Q? </li><li>内存状况Q堆内存和非堆内存用状?非堆内存通常也称怹代内存) </li></ol><div class="vspace"></div><h2>结</h2> <p><a title="" href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html" target="_blank">Inside in Jetty</a> 8.x已经各个模块拆分非常详l了。每一个模块的命名都非常有规律。通常从名UCp够猜出模块的作用? </p> <p class="vspace">部分模块可能q需要对应的配置?{jetty.home}/etc下面有大量的配置Q这些零散的配置拆分是ؓ了可复用? 如果一个jetty要想启动多个javaq程Q那么只需要指定不同的配置卛_。甚至ؓ了方便定制化Q可能ؓ每一个javaq程创徏一个完整的jetty.xml配置Q而不需?{jetty.home}/etc下面的配|? </p> </div><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/372999.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2012-04-12 09:39 <a href="http://www.dentisthealthcenter.com/xylz/archive/2012/04/12/372999.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[深入出Jetty] 文章索引http://www.dentisthealthcenter.com/xylz/archive/2012/04/12/371612.htmlimxylzimxylzThu, 12 Apr 2012 01:38:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/04/12/371612.htmlhttp://www.dentisthealthcenter.com/xylz/comments/371612.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/04/12/371612.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/371612.htmlhttp://www.dentisthealthcenter.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>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/372923.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/372923.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/372923.html</trackback:ping><description><![CDATA[Jetty提供了众多的参数和配|来保证满不同场景下的启动方式?br /> <br /> 除了极大方便嵌入式启动之外,从程序外部也非常好容易启动jetty?br /><br />[原文Qhttp://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html]<br /> <h2>q行方式</h2> <h3>q行Ҏ1</h3> 首先我们以一个标准的jarE序启动来看待这个问? <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 /> http://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>然后q行查看?/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 /> http://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><br /> ׃没有Mweb环境Q因此此时访问Q何地址应该都是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 /> http://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 http://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="http://www.dentisthealthcenter.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>q行Ҏ2</h3> <div>另外上述q行{h于:</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 /> http://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>q行Ҏ3</h3> <div>W三U方法就是用封装好的start.jarQ这个jar包封装了一些常规的配置?/div> <div><br /> 在开始之前,我们先重命名下默认的start.iniQ因为默认的配置文g会启动一个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 /> http://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 /> http://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><br /> 可以看出q个方式和第一U、第二种完全相同?/div> <div></div> <div>另外start.jar提供了一U可以查看当前运行参数的命oQ?/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 /> http://www.CodeHighlighter.com/<br /> <br /> -->java -jar start.jar --dry-run</div> <div><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 /> http://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><br /> 有意思的是这里有一个时文Ӟ/tmp/start1059041541723976621.propertiesQ里面记录了所有系l属性,也就是类似System.getProperties()?/div> <div>除非是嵌入式开发,否则我们都是用start.jar来启动jetty?/div> <h2>命o参数</h2> <div>start.jar提供了大量的参数来负责启动JVM?/div> <div>下面命o列出所有的命o行参敎ͼ</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 /> http://www.CodeHighlighter.com/<br /> <br /> -->java -jar start.jar --help</div> <div><br /> 现在问题来了Q这些默认的参数都是哪来的?例如Q如果想改变<em>${jetty.home}</em>又怎样Q?/div> <div>jetty内部默认提供了一个默认的配置文g<a target="_blank">start.config</a>来解x问题?/div> <div>默认情况下start.jar里面带有一个默认的start.config文gQ这个文件有一些预|的定义?/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 /> http://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> 文g内容非常大,其中大部分是注释?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的作用有以下几个Q?/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>定义jetty.home属?/li> <li>定义jetty启动c?/li> <li>定义jetty启动的默认配|文?/li> <li>定义OPTIONS</li> <li>Ҏ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。什么是OPTIONSQ?/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各个模块拆分成各个非常l小的模块。每一个模块(实际上是一个个的jar包)Q我们可以简单的看出是一个OPTION。而每一个OPTION都会对应于实际的jarQ这决定了q些jar包是否需要加入classpathQƈ且在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文g的语法也挺有意思的。支持一些简单的逻辑判断Q例如文件是否存在、命令行参数是否存在{?/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; ">默认情况下有如下配置Q?/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>path参数的值加入classpath</li> <li>lib参数的g为目录搜索jar包,其中的jar/zip包加入classpath</li> <li>默认的启动类是org.eclipse.jetty.xml.XmlConfiguration.classQ除非定义了start.class属?/li> <li>默认的jetty配置文g?(jetty.home)/etc/jetty.xmlQ除非传入的参数不ؓI?/li> <li>默认${jetty.home}目录是当前目录(不一定是start.jar所在\径)?{jetty.home}属性搜索顺序有Q? <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; "> <li>$(jetty.home) 参数或者系l属性(包括环境变量Q?/li> <li>. 当前路径</li> <li>.. 当前路径的父路径</li> <li>jetty-distribution/src/main/resources 当前路径的发行版子\?/li> <li>../jetty-distribution/src/main/resources 当前路径的父路径的发行版子\?/li> </ul> </li> <li>默认的classpath有: <ul style="margin-top: 0px; margin-bottom: 0px; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; "> <li>resources</li> <li>lib/jetty-xml-8.1.2.v20120308.jar</li> <li>lib/servlet-api-3.0.jar</li> <li>lib/jetty-http-8.1.2.v20120308.jar</li> <li>lib/jetty-continuation-8.1.2.v20120308.jar</li> <li>lib/jetty-server-8.1.2.v20120308.jar</li> <li>lib/jetty-security-8.1.2.v20120308.jar</li> <li>lib/jetty-servlet-8.1.2.v20120308.jar</li> <li>lib/jetty-webapp-8.1.2.v20120308.jar</li> <li>lib/jetty-deploy-8.1.2.v20120308.jar</li> <li>lib/jetty-servlets-8.1.2.v20120308.jar</li> <li>lib/jetty-util-8.1.2.v20120308.jar</li> <li>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 /> http://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="http://www.dentisthealthcenter.com/Images/dot.gif" alt="" />] [properties<img src="http://www.dentisthealthcenter.com/Images/dot.gif" alt="" />] [configs<img src="http://www.dentisthealthcenter.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列表Q这指的是命令行参数Q不是模块,由此可见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>--version 列出版本?/li> <li>--list-options 列出当前start.config支持的所有OPTIONS</li> <li>--list-config 列出当前start.config内容Q文本内容)</li> <li>--dry-run 列出当前配置要启动的javaq程完整参数Q不启动jetty服务Q?/li> <li>--exec 启动子进E(只有启动子进E才能修?XQ?D{参敎ͼ因ؓstart.jar本n是依靠javaq程启动的,不能在运行时改变Q?/li> <li>--stop 停止q行的jetty实例</li> <li>--daemon 后台q行jettyQ启动将stdout/stderr记录?{jetty.log}/start.log中(好了Q这个变量jetty.log没有默认配置说明Q估计是${jetty.home}/logs目录Q?/li> <li>--config=<file> 指定特别的start.configQ以便覆盖内|的start.config.(l过试Q如果指定此文gQ那么内|的配置不再读取,q导致必d所有配|写全,包括mainclass/jetty config/OPTIONS{)</li> <li>--ini=<file> 从配|文件中装蝲命o行参数。上面参C及下面提到的参数是在太多Q可以从配置文g中一ơ性加载,默认的配|文件是${jetty.home}/start.ini?/li> <li>--pre=<file> 指定特别的jettyq行配置文gQ这个配|文件在后面提高的配|文件前面运行,相当于改变默认的装蝲机制?/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; ">属性分成两U,一U是会传递给pȝ属性(java.lang.System#getProperty(String)),一U只是作为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; ">如果要传递给pȝ属性,则格式是Q?-Dname=valueQ和javaq程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; ">jetty也有一些默认的pȝ属性:</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>cd</th><th>描述</th> </tr> <tr> <td>org.eclipse.jetty.util.log.class</td> <td>class</td> <td>jetty日志记录Q默认ؓQorg.eclipse.jetty.util.log.Slf4jLog</td> </tr> <tr> <td>org.eclipse.jetty.util.log.DEBUG</td> <td>boolean</td> <td>调试日志输出地方Q默认ؓstderr和java内置的LoggerQ如果是其他日志则需要设|ؓtrueQ默认ؓfalse</td> </tr> <tr> <td>org.eclipse.jetty.util.log.IGNORED</td> <td>boolean</td> <td>是否记录一些忽略的错误日志Q默认ؓfalse</td> </tr> <tr> <td>org.eclipse.jetty.util.log.SOURCE</td> <td>boolean</td> <td>记录错误日志行号Q位|?默认为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=valueQ注意这里没?D了。这些参C会传递给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; ">所有参数列表:</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>path=[directory]: 传递额外的classpathQ参考上面默认的start.config配置</li> <li>lib=[directory]: 传递额外classpath搜烦jar/zip的目?/li> <li>STOP.PORT=[number]: 停止jetty的端口(q程理Q?/li> <li>STOP.KEY=[alphanumeric]: 停止jetty的密码(q程理Q?/li> <li>DEBUG=true: 是否启动调试模式Q同时会讄org.eclipse.jetty.util.log.DEBUG属性ؓtrueQ默认ؓfalse</li> <li>OPTIONS=[option,option...]: OPTION列表Q也是要启动的模块列表?/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>All</li> <li>Client</li> <li>Server</li> <li>ajp</li> <li>annotations</li> <li>client</li> <li>default</li> <li>deploy</li> <li>ext</li> <li>jmx</li> <li>jndi</li> <li>jsp</li> <li>jta</li> <li>monitor</li> <li>overlay</li> <li>overlays</li> <li>plus</li> <li>policy</li> <li>resources</li> <li>rewrite</li> <li>security</li> <li>server</li> <li>servlet</li> <li>servlets</li> <li>setuid</li> <li>webapp</li> <li>websocket</li> <li>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; ">jettyq行需要一些配|文Ӟq些配置文g对应于不同的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中,所有配|文件列表有Q?/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>etc/jetty-ajp.xml</li> <li>etc/jetty-annotations.xml</li> <li>etc/jetty-bio-ssl.xml</li> <li>etc/jetty-bio.xml</li> <li>etc/jetty-contexts.xml</li> <li>etc/jetty-debug.xml</li> <li>etc/jetty-deploy.xml</li> <li>etc/jetty-fileserver.xml</li> <li>etc/jetty-ipaccess.xml</li> <li>etc/jetty-jmx.xml</li> <li>etc/jetty-logging.xml</li> <li>etc/jetty-monitor.xml</li> <li>etc/jetty-overlay.xml</li> <li>etc/jetty-plus.xml</li> <li>etc/jetty-policy.xml</li> <li>etc/jetty-proxy.xml</li> <li>etc/jetty-requestlog.xml</li> <li>etc/jetty-rewrite.xml</li> <li>etc/jetty-ssl.xml</li> <li>etc/jetty-stats.xml</li> <li>etc/jetty-testrealm.xml</li> <li>etc/jetty-webapps.xml</li> <li>etc/jetty-xinetd.xml</li> <li>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; ">q么多配|,如何记得住?该用哪些配|?</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; ">下一个章节中介绍配置文g?br /> </p> <br /> 参考资源:<br /> <ul> <li><a href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/09/371598.html" target="_blank">[深入出Jetty 03] 单的RESTful入门</a></li> <li><a href="http://www.dentisthealthcenter.com/xylz/archive/2012/01/29/368970.html" target="_blank">[深入出Jetty 02] Jetty 8.x 单试?/a></li> <li><a href="http://www.dentisthealthcenter.com/xylz/archive/2012/01/29/368969.html" target="_blank">[深入出Jetty 01] Jetty 8.x 安装</a></li> </ul><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/372923.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2012-03-28 19:02 <a href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/28/372923.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一ơ简单却致命的错?/title><link>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2012/03/15/371966.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/371966.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2012/03/15/371966.html#Feedback</comments><slash:comments>16</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/371966.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/371966.html</trackback:ping><description><![CDATA[U上服务器负载过高发生了报警Q同事找我求救?br />我看到机器的负蝲都超q?0了,查看javaq程U程栈,扑ֈ了出问题的代码?br /> <br /> 下面是其代码片段Q实际情况错误处理比q更坏?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 /> http://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 = "http://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 /> 思考下Q这D代码有什?strong style="background-color: yellow; ">致命</strong>问题么?Q这里不q究业务逻辑处理的正性以及细的瑕疵Q?br /> .<br /> ..<br /> ...<br /> 现在回来?br /> 我发现线E栈里面的线E都RUNNABLE?2行?br /> q一行看h有什么问题呢QStringBuilder.toString()不是转换成String么?Apache commons-lang里面的StringUtils.isNotEmpty使用也没问题啊?<br /> 看代码,人家的逻辑其实是判断是否是W一行,如果不是W一行那么就增加一个换行符?br /> <br /> 既然CPU在这里运行,那么p明这个地方一定存在非常耗费CPU的操作,DCPU非常J忙Q从而系l负载过高?br /> 看详l堆栈,其实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 /> http://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 /> http://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构造函数的最后一行,valueq不是直接指向的Q而是重新生成了一个新的字W串Q用系l拷贝函数进行内存复制?br /> <div><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 /> http://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 /> 好了Q再回头看逻辑代码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 /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000FF; ">if</span> (StringUtils.isNotEmpty(buf.toString())) {<br />     buf.append("\r\n");<br /> }</div> q里有问题的地方在于每次循环一行的时候都生成一个新的字W串。也是说如果HTTPq回的结果输入流中有1000行的话,额外生?000个字W串Q不StringBuilder扩容生成的个敎ͼ。每一个字W串q比前一个字W串大?br /> <br /> <br /> 我们来做一个简单的试Q我们在原来的代码上增加几行计数代码?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 /> http://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以及额外发生的字W串拯大小malloc?br /> q是一ơ输出的l果?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 /> http://www.CodeHighlighter.com/<br /> <br /> -->1169 -> 66958 -> 39356387</div> 也就?169行的|页Q一共是66958字节Q?5KBQ,l果额外生成的内存大(不算StringBuilder扩容占用的内存大)?9356387字节Q?7.5MB)!!!<br /> 试想一下,CPU一直频J于q行内存分配Q机器的负蝲能不高么Q我们线上服务器?个CPU 16核,内存24G的Redhat Enterprise Linux 5.5Q负载居然达到几十。这q是只有讉K量很低的时候。这难怪服务频J宕Z?br /> <br /> 事实上我们有非常完善和丰富的ZApache commons-httpclient的封装,操作h也非常简单。对于这U简单的hQ只需要一条命令就解决了?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 /> http://www.CodeHighlighter.com/<br /> <br /> -->String platform.utils.HttpClientUtils.getResponse(String)<br /> String platform.utils.HttpClientUtils.postResponse(String, Map<String, String>)</div> <br /> 即非要自造轮子,处理q种单的输入可以用下面的代码Q就可以很好的解决问题?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 /> http://www.CodeHighlighter.com/<br /> <br /> -->    InputStream in = <img src="http://www.dentisthealthcenter.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 /> http://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 /> q个问题非常单,只是惌辑և个观点:<br /> <ul> <li>团队更需要合作,按照规范来进行。自造轮子不是不可以Q但是生产环境还是要限于自己熟悉的方式?/li> <li>即非常单的代码Q也有可能有致命的陷阱在里面。善于思考才是王道?/li> <li>学习开源的代码和常规思\Q学习解决问题的常规做法。这个问题其实非常简单,熟悉输入输出的人非常熟l就能解决问题?/li> </ul><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/371966.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2012-03-15 18:30 <a href="http://www.dentisthealthcenter.com/xylz/archive/2012/03/15/371966.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[深入出Jetty 03]单的RESTful入门http://www.dentisthealthcenter.com/xylz/archive/2012/03/09/371598.htmlimxylzimxylzFri, 09 Mar 2012 09:52:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/03/09/371598.htmlhttp://www.dentisthealthcenter.com/xylz/comments/371598.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/03/09/371598.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/371598.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/371598.html
    目地址Q?a >https://github.com/adyliu/jetty-rest-demo 

    文g列表


    包含如下文gQ?/p>

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

    Maven配置

    Z能够方便从jetty:run来启动web容器Q用jetty的maven插g?br />需要特别注意的是,从jetty7.5.3开始就必须用maven 3了,以前使用的maven 2不能使用了,׃ؓ了这问题Q我跟踪了很久,大囧?br />q里使用jetty最新的maven插gQ同样会启动最新的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

    q是一个简单的web.xml配置Q主要配|spring servlet。当然这里也辅助配置了一个log4jQ方便查看日志输出,不配|也没关pR?br />另外也没有用servlet 3.0的配|?br />
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/j2ee http://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的渲染映(其实q个例子中没有用刎ͼ?br />
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context
    ="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation
    ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
                http://www.springframework.org/schema/mvc http://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

    下蝲开始写W一个ControllerQ当然这个ControllerE微有一点点别扭?br />直接q回字符Ԍ另外烦引页映射C个字W串上。(也不对中文进行处理)

    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

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

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

    Resources



    imxylz 2012-03-09 17:52 发表评论
    ]]>
    ICE Mini Guidehttp://www.dentisthealthcenter.com/xylz/archive/2012/02/29/370971.htmlimxylzimxylzWed, 29 Feb 2012 02:44:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/02/29/370971.htmlhttp://www.dentisthealthcenter.com/xylz/comments/370971.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/02/29/370971.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/370971.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/370971.htmlICE中间件?br />
    ICE作ؓ一个异构^収ͼ提供了高性能的RPC解决Ҏ。全q指定的架构计划中就是将现有的内部通讯方式q移到ICE+Protocol Buffers的组合方案中?br /> 我们可能的利用Zookeeper的配|管理,创徏更透明的客L代理Q同时也是降低开发的隑ֺ?br /> 我们慢慢试Q寻找更适合我们的分布式通讯中间件?br />
    下面的Slide是一简短的入门介绍。目前ؓ止,我们的开发还是仅限于Java语言的服务端。以后视情况提供一些其它语a的服务端吧?br /> 关键字:ICE "The Internet Communications Engine" RPC "Protocol Buffers"

    imxylz 2012-02-29 10:44 发表评论
    ]]>
    搜狐技术部长期招聘Java工程?高工程?初架构?目l理/技术主?/title><link>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2012/02/16/366663.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/366663.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2012/02/16/366663.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/366663.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/366663.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12pt; ">业务发展需要,对h才的渴望Q对事业的追求,搜狐技术部需要一些高Uh才?/span><br /> <span style="font-size: 12pt; "> 今年C招努力不再拘于形式Q只要是人才Q双Ҏ意愿的,我们都努力去争取?/span><br /> <br /> <span style="font-size: 12pt; ">北京地点Q北?五道?/span><br /> <span style="font-size: 12pt; ">工作l验Q不限,应届生都可以Q我们有工作十年以上的h才,也需要这Uh才?/span><br /> <span style="font-size: 12pt; "> 待遇斚wQ努力跟上物L水^。常规在10K~30K?/span><br /> <span style="font-size: 12pt; "> 技术要求:以Java语言ZQ要求对基本的技术、概c理论、框枉需要有一定的深度。根据经验,仅仅是靠忽悠和项目数量是不行的?/span><br /> <span style="font-size: 12pt; "> 产品要求Q要求对L的互联网产品都有认识Q对用户体验有一定的理解。对于非应届生,我们更偏重于用互联网技术经验(不是企业WEBpȝ斚wQ?/span><br /> <span style="font-size: 12pt; "> 扩展要求Q要求有gmail/twitter/stackoverflow/github帐号。有开源A献的特别考虑?/span><br /> <span style="font-size: 12pt; "> 创新要求Q能够掌握python/ruby/perl/Erlang{一两种脚本语言Z?/span><br /> <span style="font-size: 12pt; "> 工作领域Q我们有挑战的领域有大规模数据集、高性能异步通讯、v量数据处理、分布式存储与缓存、ƈ行计、高q发处理{?/span><br /> <br /> <br /> <span style="font-size: 12pt; ">我们Ƣ迎有志向于互联|的同学加入。技术要求不高,但要有思想、有深度、热׃联网?/span><br /> <span style="font-size: 12pt; ">有兴发送简历到Q?/span><span style="font-size: 12pt; color: #ff0000; "><strong>已过?/strong></span><br /> <br /> <br /> <span style="font-size: 12pt; ">我们长期招聘q类人才Q只要是人才Q我们都愿意提供盔R应的环境?br /><strong>另外Q也非常需要一个前端主,负责理整个团队的前端技术h才和基础架构?/strong><br /><strike>【最后更新时_2012/11/01?br /></strike><br /></span></div><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/366663.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2012-02-16 11:10 <a href="http://www.dentisthealthcenter.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 CHMhttp://www.dentisthealthcenter.com/xylz/archive/2012/02/08/369608.htmlimxylzimxylzWed, 08 Feb 2012 08:41:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/02/08/369608.htmlhttp://www.dentisthealthcenter.com/xylz/comments/369608.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/02/08/369608.html#Feedback1http://www.dentisthealthcenter.com/xylz/comments/commentRss/369608.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/369608.html
    L了发生错误的javascriptQ网l原因,你懂的)Q烦引排序重命名Q稍微排版了下?br />
    没有改动M内容?strong style="font-family: 'Comic Sans MS'; font-size: 14pt; color: #0000ff; ">毫无疑问Q这是英文版的,因ؓ没有人翻译?/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>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2012/01/29/368970.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/368970.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2012/01/29/368970.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/368970.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/368970.html</trackback:ping><description><![CDATA[<h1>Jetty 8.x 单试?/h1><h2>q行</h2><p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">安装好了以后Q在jetty的主目录下,q行h?/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.iniQ这是典型的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>q程讉K</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端口Q访问下看看?/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; ">http://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发布的时候比较粗p,q些l节都没有处理好。事实上Q官方站点上的文章都是和jetty7.x有关的,没有更新?.x版本?br /><img src="http://www.dentisthealthcenter.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; ">好在有一行提CQ如果要q程讉K的话Q需要开启一个设|。好吧,按照说明Q将默认test.war的远E访问模式打开?修改文g$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 />http://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 />q里已经默认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="http://www.dentisthealthcenter.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; ">昄Q这样就已经支持q程讉K了?/p><div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div><h2>Servlet讉K</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的ServletQ它可以查看当前h的Request/Session/Cookie信息。我们简单看一下Requesth?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="http://www.dentisthealthcenter.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; ">q里面的信息非常丰富Q这Z后调试当前请求信息提供了很方便的样例?/p><div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div><h2>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里面有两Ucomet模型Q一U是常见的长q接(Long Polling), 另一U就是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模型。在q种方式下,览器定时发起一个长q接Q等待服务器q回。一ơ请求完了以后仍然会发v一个新的请求,L有一个连接保持双方的通讯?下图描述了此效果?br /><img src="http://www.dentisthealthcenter.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="http://www.dentisthealthcenter.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; ">有意思的是,q里的请求头和响应头有一些特D的标识。以后涉及到websocket的时候再来研I?br /><img src="http://www.dentisthealthcenter.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; ">l测试,我机器上的chrome 18.0,firefox 8.0都支持websocket的,而IE9仍然不支持?br /><br /><img src="http://www.dentisthealthcenter.com/images/blogjava_net/xylz/jetty-firefox.png" alt="" /><br /></p><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/368970.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2012-01-29 16:41 <a href="http://www.dentisthealthcenter.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 安装http://www.dentisthealthcenter.com/xylz/archive/2012/01/29/368969.htmlimxylzimxylzSun, 29 Jan 2012 08:34:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2012/01/29/368969.htmlhttp://www.dentisthealthcenter.com/xylz/comments/368969.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2012/01/29/368969.html#Feedback0http://www.dentisthealthcenter.com/xylz/comments/commentRss/368969.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/368969.htmlJetty?.x已经q移到eclipse下了Q从eclipse的下载目录开始安装吧?/p>

    最新的发布版本?.1.0.v20120127Q我们从q个版本开始?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

    附录



    imxylz 2012-01-29 16:34 发表评论
    ]]>
    深入出 Java Concurrency (40): q发ȝ part 4 性能与׾~?/title><link>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2011/12/31/367641.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/367641.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2011/12/31/367641.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/367641.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/367641.html</trackback:ping><description><![CDATA[<h1>性能与׾~?/h1> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">使用U程的一U说法是Z提高性能。多U程可以使程序充分利用闲|的资源Q提高资源的利用率,同时能够q行处理dQ提高系l的响应性?但是很显Ӟ引入U程的同时也引入了系l的复杂性。另外系l的性能q不是L随着U程数的增加而L提高?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2>性能与׾~?/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周期、内存、网l带宽、磁盘IO、数据库、WEB服务{等?引入多线E可以充分利用多核的优势Q充分利用IOd带来的gq,也可以降低网l开销带来的媄响,从而提高单位时间内的响应效率?/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; ">Z提高性能Q需要有效的利用我们现有的处理资源,同时也要开拓新的可用资源。例如,对于CPU而言Q理想状况下希望CPU能够满负荷工作。当然这里满负荷工作是指做有用的事情Q而不是无谓的d@环或者等待。受限于CPU的计能力,如果CPU辑ֈ了极限,那么很显然我们充分利用了计算能力。对于IO而言Q内存、磁盘、网l等Q,如果辑ֈ了其对于的带宽,q些资源的利用率也就上去了。理想状况下所有资源的能力都被用完了,那么q个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; ">Z衡量pȝ的性能Q有一些指标用于定性、定量的分析。例如服务时间、等待时间、吞吐量、效率、可伸羃性、生成量{等。服务时间、等待时间等用于衡量pȝ的效率,卛_底有多快。吞吐量、生成量{用于衡量系l的定wQ即能够处理多少数据。除此之外,有效服务旉、中断时间等用于能力pȝ的可靠性和E_性等?/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>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; ">q行的Q务增加资源显然能够提高性能Q但是如果是串行的Q务,增加资源q不一定能够得到合理的性能提升?nbsp;<a rel="nofollow" style="text-decoration: none; ">Amdahl定律</a>描述的在一个系l中Q增加处理器资源对系l行的提升比率?假定在一个系l中QF是必M行化执行的比重,N是处理器资源Q那么随着N的增加最多增加的加速比Q?/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="http://www.dentisthealthcenter.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近于无I大Ӟ加速比最大值无限趋q于1/F?q意味着如果一个程序的串行化比重ؓ50%Q那么ƈ行化后最大加速比?倍?/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%Q那么CPU的资源每ơ翻倍时Q加速比也应该翻倍?事实上,在拥?0个处理器的系l中Q程序如果有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的利用率。下图描q的是随着CPU的数量增加,不同串行化比重的pȝ的加速比?/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="http://www.dentisthealthcenter.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; ">很显Ӟ串行比重大Q增加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>性能提升</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">性能的提升可以从以下几个斚w入手?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>pȝq_的资源利用率</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ȝq_的资源利用率是指某一个设备繁忙且服务于此E序的时间占所有时间的比率。从物理学的角度讲类g有用功的比率。简单的说就是:资源利用?有效J忙旉/总耗费旉?/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%的用率Q但不一定是有效的工作。有效性通常难以衡量Q通常只能以主观来评估Q或者通过被优化的E序的行为来判断是否提高了有效性?/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; ">延迟描述的是完成d所耗费的时间。gq有时候也成ؓ响应旉。如果有多个q行的操作,那么延迟取决于耗费旉最大的d?/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ȝ上同时执行多个进E或者多个程序的能力。多处理能力的好处是可以提高吞吐量。多处理可以有效利用多核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>多线E?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">多线E描q的是同一个地址I间内同时执行多个线E的q程。这些线E都有不同的执行路径和不同的栈结构。我们说的ƈ发性更多的是指针对U程?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>q发?/h3> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">同时执行多个E序或者Q务称之ؓq发。单E序内的多Q务处理或者多E序间的多Q务处理都认ؓ是ƈ发?/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; ">吞吐量衡量系l在单位之间内可以完成的工作总量。对于硬件系l而言Q吞吐量是物理介质的上限。在没有辑ֈ物理介质之前Q提高系l的吞吐量也可以大幅度改q性能。同时吞吐量也是衡量性能的一个指标?/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; ">E序q行q程中性能最差的地方。通常而言Q串行的IO、磁盘IO、内存单元分配、网lIO{都可能造成瓉。某些用太频繁的算法也有可能成为瓶颈?/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; ">q里的可扩展性主要是指程序或pȝ通过增加可用的资源而增加性能的能力?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2>U程开销</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">假设引入的多U程都用于计,那么性能一定会有很大的提升么? 其实引入多线E以后也会引入更多的开销?/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; ">如果可运行的U程数大于CPU的内核数Q那么OS会根据一定的调度法Q强行切换正在运行的U程Q从而其它U程能够使用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; ">切换U程会导致上下文切换。线E的调度会导致CPU需要在操作pȝ和进E间p更多的时间片D,q样真正执行应用E序的时间就减少了。另外上下文切换也会D~存的频J进出,对于一个刚被切换的U程来说Q可能由于高速缓冲中没有数据而变得更慢,从而导致更多的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; ">不同U程间要q行数据同步Qsynchronized以及volatile提供的可见性都会导致缓存失效。线E栈之间的数据要和主存进行同步,q些同步有一些小的开销。如果线E间同时要进行数据同步,那么q些同步的线E可能都会受阅R?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h3>d</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|的线E会Dd。通常d的线E可能在JVM内部q行自旋{待Q或者被操作pȝ挂v。自旋等待可能会D更多的CPU切片费Q而操作系l挂起则会导致更多的上下文切换?/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; ">了解了性能的提升的几个斚wQ也了解性能的开销后,应用E序pҎ实际的场景进行取舍和评估。没有一x逸的优化ҎQ不断的q行范围改q和调整是提高性能的有效手Dc当前一些大的架构调整也会导致较大的性能的提升?/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; ">单的原则是在保证逻辑正确的情况小Q找到性能瓉Q小步改q和优化?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2>参考资?/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>Amdahl's law: <a rel="nofollow" style="text-decoration: none; ">http://en.wikipedia.org/wiki/Amdahl%27s_law</a></li> <li>Gustafson's law: <a rel="nofollow" style="text-decoration: none; ">http://en.wikipedia.org/wiki/Gustafson%27s_law</a></li> <li>Sun-Ni law: <a rel="nofollow" style="text-decoration: none; ">http://en.wikipedia.org/wiki/Sun-Ni_law</a></li> <li>多核pȝ中三U典型锁竞争的加速比分析 <a rel="nofollow" style="text-decoration: none; ">http://blog.csdn.net/drzhouweiming/article/details/1800319</a></li> <li>阿姆辑ְ定律和Gustafson定律的等h?nbsp;<a rel="nofollow" style="text-decoration: none; ">http://book.51cto.com/art/201004/197506.htm</a></li> </ul> <p> </p> <div id="index"> <div id="previous"><a href="http://www.dentisthealthcenter.com/xylz/archive/2011/12/30/367592.html">q发ȝ part 3 常见的ƈ发陷?/a> </div> <div id="center" align="center"><a href="http://www.dentisthealthcenter.com/xylz/archive/2010/07/08/325587.html"><strong>?nbsp;  ?/strong></a> </div> <div id="next"><a name="over">暂时完结</a></div> </div><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/367641.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2011-12-31 14:13 <a href="http://www.dentisthealthcenter.com/xylz/archive/2011/12/31/367641.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入出 Java Concurrency (39): q发ȝ part 3 常见的ƈ发陷?/title><link>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2011/12/30/367592.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/367592.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2011/12/30/367592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/367592.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/367592.html</trackback:ping><description><![CDATA[<h1>常见的ƈ发陷?/h1> <h2>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只能数据的可见性,q不能保证原子操作和U程安全Q因此volatile不是万能的。参?a href="http://www.dentisthealthcenter.com/xylz/archive/2010/07/03/325168.html" rel="nofollow" style="text-decoration: none; ">指o重排?/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最常见于下面两U场景?/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 /> http://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="http://www.dentisthealthcenter.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. 单例模型 Q?a href="http://www.dentisthealthcenter.com/xylz/archive/2009/12/18/306622.html%ef%bc%89" rel="nofollow" style="text-decoration: none; ">http://www.dentisthealthcenter.com/xylz/archive/2009/12/18/306622.htmlQ?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 /> http://www.CodeHighlighter.com/<br /> <br /> --><a href="http://www.dentisthealthcenter.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><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; ">看v来Lock有更好的性能以及更灵zȝ控制Q是否完全可以替换synchronizedQ?/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="http://www.dentisthealthcenter.com/xylz/archive/2010/07/16/326246.html" rel="nofollow" style="text-decoration: none; ">锁的一些其它问?/a>中说q,synchronized的性能随着JDK版本的升U会来高Q而Lock优化的空间受限于CPU的性能Q很有限。另外JDK内部的工PU程转储Q对synchronized是有一些支持的Q方便发现死锁等Q,而对Lock是没有Q何支持的?/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完全没有问题Q随着机器的性能的提高,q点开销是可以忽略的。而且从代码结构上讲是更简单的。简单就是美?/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; ">对于复杂的逻辑Q如果涉及到d锁、条件变量、更高的吞吐量以及更灉|、动态的用法Q那么就可以考虑使用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 /> http://www.CodeHighlighter.com/<br /> <br /> -->Lock lock = <img src="http://www.dentisthealthcenter.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块中Q否则一旦发生异常或者逻辑跌{Q很有可能会D锁没有释放,从而发生死锁。而且q种死锁是难以排查的?/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无法做到的尝试锁机制Q或者说担心发生死锁无法自恢复,那么使用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 /> http://www.CodeHighlighter.com/<br /> <br /> -->Lock lock = <img src="http://www.dentisthealthcenter.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; ">甚至可以使用获取锁一D|间内时的机制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>锁的边界</h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">一个流行的错误是这L?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 /> http://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 /> 看v来很合理的,对于一个线E安全的Map实现Q要存取一个不重复的结果,先检是否存在然后加入?其实我们知道两个原子操作和在一L指o序列不代表就是线E安全的?割裂的多个原子操作放在一起在多线E的情况下就有可能发生错误?/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;原子操作”机制Q这{h于下面的逻辑Q?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 /> http://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 /> 除了putIfAbsentq有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; ">提到MapQ这里有一谈<a href="http://www.dentisthealthcenter.com/xylz/archive/2009/12/18/306602.html" rel="nofollow" style="text-decoration: none; ">HashMapdq发</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>构造函数启动线E?/h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">下面的实例是在构造函C启动一个线E?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 /> http://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 /> q里可能存在的陷阱是如果此类被承,那么启动的线E可能无法正读取子cȝ初始化操作?/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; ">因此一个简单的原则是,止在构造函C启动U程Q可以考虑但是提供一个方法来启动U程。如果非要这么做Q最好将c设|ؓfinalQ禁止ѝ?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2>丢失通知的问?/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="http://www.dentisthealthcenter.com/xylz/archive/2011/09/05/326988.html" rel="nofollow" style="text-decoration: none; ">q篇文章</a>里面提到qnotify丢失通知的问题?/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/singalAllQ如果不定到底是否能够正确的收到消息,担心丢失通知Q简单一点就是L通知所有?/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; ">如果担心只收Cơ消息,使用循环一直监听是不错的选择?/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; ">非常ȝ性能的系l,可能需要区分到底是通知单个q是通知所有的挂v者?/p> <div style="margin-top: 1.33em; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; "></div> <h2>U程?/h2> <p style="margin-top: 0px; margin-bottom: 0px; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 19px; background-color: #ffffff; ">q不是线E数多好Q在下一文章里面会具体了解下性能和可伸羃性?单的_U程数多没有一个固定的l论Q受限于CPU的内核数QIO的性能以及依赖的服务等{。因此选择一个合适的U程数有助于提高吞吐量?/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密集型应用,U程数和CPU的内核数一致有助于提高吞吐量,所有CPU都很J忙Q效率就很高?对于IO密集型应用,U程数受限于IO的性能Q某些时候单U程可能比多U程效率更高。但通常情况下适当提高U程敎ͼ有利于提高网lIO的效率,因ؓ我们L认ؓ|络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; ">对于U程池而言Q选择合适的U程C及Q务队列是提高U程池效率的手段?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 /> http://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 /> 对于U程池来_如果dL有积压,那么可以适当提高corePoolSize大小Q如果机器负载较低,那么可以适当提高maximumPoolSize的大;d队列不长的情况下减小keepAliveTime的时间有助于降低负蝲Q另外Q务队列的长度以及d队列?a href="http://www.dentisthealthcenter.com/xylz/archive/2011/01/18/343183.html" rel="nofollow" style="text-decoration: none; ">拒绝{略</a>也会对Q务的处理有一些媄响?/p> <p> </p> <div id="index"> <div id="previous"><a href="http://www.dentisthealthcenter.com/xylz/archive/2011/12/29/367480.html">q发ȝ part 2 常见的ƈ发场?/a> </div> <div id="center" align="center"><a href="http://www.dentisthealthcenter.com/xylz/archive/2010/07/08/325587.html"><strong>?nbsp;  ?/strong></a> </div> <div id="next"><a href="http://www.dentisthealthcenter.com/xylz/archive/2011/12/31/367641.html">q发ȝ part 4 性能与׾~?/a> </div> </div><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/367592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2011-12-30 17:25 <a href="http://www.dentisthealthcenter.com/xylz/archive/2011/12/30/367592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入出 Java Concurrency (38): q发ȝ part 2 常见的ƈ发场?/title><link>http://www.dentisthealthcenter.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>http://www.dentisthealthcenter.com/xylz/archive/2011/12/29/367480.html</guid><wfw:comment>http://www.dentisthealthcenter.com/xylz/comments/367480.html</wfw:comment><comments>http://www.dentisthealthcenter.com/xylz/archive/2011/12/29/367480.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.dentisthealthcenter.com/xylz/comments/commentRss/367480.html</wfw:commentRss><trackback:ping>http://www.dentisthealthcenter.com/xylz/services/trackbacks/367480.html</trackback:ping><description><![CDATA[     摘要: U程?<br> <br>q发最常见用于U程池,昄使用U程池可以有效的提高吞吐量?<br>最常见、比较复杂一个场景是Web容器的线E池。Web容器使用U程池同步或者异步处理HTTPhQ同时这也可以有效的复用HTTPq接Q降低资源申L开销。通常我们认ؓHTTPh旉常昂늚Qƈ且也是比较耗费资源和性能的,所以线E池在这里就扮演了非帔R要的角色?<br>在线E池的章节中非常详细的讨ZU程池的原理和用,同时也提CQ线E池的配|和参数Ҏ能的媄响是巨大的。不如此,受限于资源(机器的性能、网l的带宽{等Q、依赖的服务Q客L的响应速度{,U程池的威力也不会一直增ѝ达CU程池的瓉后,性能和吞吐量都会大幅度降低?<br>一直增加机器的性能或者增大线E的个数Qƈ不一定能有效的提高吞吐量。高q发的情况下Q机器的负蝲会大q提升,q时候机器的E_性、服务的可靠性都会下降?<br>管如此Q线E池依然是提高吞吐量的一个有效措施,配合合适的参数能够有效的充分利用资源,提高资源的利用率?nbsp; <a href='http://www.dentisthealthcenter.com/xylz/archive/2011/12/29/367480.html'>阅读全文</a><img src ="http://www.dentisthealthcenter.com/xylz/aggbug/367480.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.dentisthealthcenter.com/xylz/" target="_blank">imxylz</a> 2011-12-29 16:31 <a href="http://www.dentisthealthcenter.com/xylz/archive/2011/12/29/367480.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入出 Java Concurrency (37): q发ȝ part 1 死锁与活跃度http://www.dentisthealthcenter.com/xylz/archive/2011/12/29/365149.htmlimxylzimxylzThu, 29 Dec 2011 06:04:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/12/29/365149.htmlhttp://www.dentisthealthcenter.com/xylz/comments/365149.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/12/29/365149.html#Feedback2http://www.dentisthealthcenter.com/xylz/comments/commentRss/365149.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/365149.html
    前面谈了很多q发的特性和工具Q但是大部分都是和锁有关的。我们用锁来保证线E安全,但是q也会引起一些问题?
    锁顺序死?lock-ordering deadlock)Q多个线E试N过不同的顺序获得多个相同的资源Q则发生的@环锁依赖现象?
    动态的锁顺序死锁(Dynamic Lock Order DeadlocksQ:多个U程通过传递不同的锁造成的锁序死锁问题?
    资源死锁QResource DeadlocksQ:U程间相互等待对Ҏ有的锁,q且谁都不会释放自己持有的锁发生的死锁。也是说当现场持有和等待的目标成ؓ资源Q就有可能发生此死锁。这和锁序死锁不一L地方是,竞争的资源之间ƈ没有严格先后序Q仅仅是怺依赖而已?nbsp; 阅读全文

    imxylz 2011-12-29 14:04 发表评论
    ]]>
    ~程语言大战http://www.dentisthealthcenter.com/xylz/archive/2011/12/06/365658.htmlimxylzimxylzTue, 06 Dec 2011 03:25:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/12/06/365658.htmlhttp://www.dentisthealthcenter.com/xylz/comments/365658.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/12/06/365658.html#Feedback8http://www.dentisthealthcenter.com/xylz/comments/commentRss/365658.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/365658.html


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



    iPhone/iPad的热销让Object Cl箋火热Q前十的位置q是可以持箋很久的,q一Ҏ庸置疑。移动设备开发的高端人才现在是高薪难求,如果有时间我也要l箋x下?nbsp; 阅读全文

    imxylz 2011-12-06 11:25 发表评论
    ]]>
    处理Zookeeper的sessionq期问题http://www.dentisthealthcenter.com/xylz/archive/2011/12/05/365578.htmlimxylzimxylzMon, 05 Dec 2011 05:57:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/12/05/365578.htmlhttp://www.dentisthealthcenter.com/xylz/comments/365578.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/12/05/365578.html#Feedback8http://www.dentisthealthcenter.com/xylz/comments/commentRss/365578.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/365578.htmlSession失效问题

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

    imxylz 2011-12-05 13:57 发表评论
    ]]>
    Redis 2.2.x 升?.4.xhttp://www.dentisthealthcenter.com/xylz/archive/2011/11/21/364457.htmlimxylzimxylzMon, 21 Nov 2011 08:48:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/11/21/364457.htmlhttp://www.dentisthealthcenter.com/xylz/comments/364457.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/11/21/364457.html#Feedback1http://www.dentisthealthcenter.com/xylz/comments/commentRss/364457.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/364457.html

    有h说Redis的作者是一个勤奋的人,p同意Q?


    本来升是ؓ了增加批量操作从而提高性能Q没惛_内存占用节省了很多?

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

    imxylz 2011-11-21 16:48 发表评论
    ]]>
    兑现http://www.dentisthealthcenter.com/xylz/archive/2011/10/10/360915.htmlimxylzimxylzMon, 10 Oct 2011 14:44:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/10/10/360915.htmlhttp://www.dentisthealthcenter.com/xylz/comments/360915.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/10/10/360915.html#Feedback3http://www.dentisthealthcenter.com/xylz/comments/commentRss/360915.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/360915.html

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


    写一技术博客需要大量的技术储备,同时自动亲自动手d践,证实惌C的Q发现要回避的问题,q需要将自己体验的过E记录下来,以便后来够避免类似的问题?/p>


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


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


    而我现在更喜Ƣ更新UWiki式的技术判断,作ؓҎ的积累。没有压力,没有负担Q随心随意?/p>


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



    imxylz 2011-10-10 22:44 发表评论
    ]]>Ganglia安装指南 (ZCentOS 5.6)http://www.dentisthealthcenter.com/xylz/archive/2011/07/21/354744.htmlimxylzimxylzWed, 20 Jul 2011 16:34:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/07/21/354744.htmlhttp://www.dentisthealthcenter.com/xylz/comments/354744.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/07/21/354744.html#Feedback7http://www.dentisthealthcenter.com/xylz/comments/commentRss/354744.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/354744.html

    Ganglia安装指南 (ZCentOS 5.6)

    安装依赖

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

    如果上述安装p|Q可能需要安装以下库依赖

    yum install zlib freetype libart_lgpl libpng
    

    安装rrdtools

    http://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依赖

    http://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位操作系l,需要手动的拯下动态链接库到lib64?/p>

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

    安装apr以及apr-util

    http://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
    
    http://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

    http://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的话Q安装下 yum install pcre 下蝲ganglia-3.2.0Q解压,安装

    ./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数据目录Q看$ganglia-3.2.0/web/conf.php里面的gmetad_root变量QƈҎapache的运行用户创建权限,例如apacheq行于apache用户??/p>

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

    配置一个数据源Q修?etc/ganglia/gmetad.conf文gQ同时将q行用户讄为rrdtool的目录权限用P例如apache用户

    data_source "suc" localhost
    setuid_username "apache"
    

    其中suc是数据源的名Uͼ客户端分l会依赖此名Uͼ后面会提到?d自启动脚?/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节点Q?/h2>

    本机安装如下Q?/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是将要在服务端进行的分组Q是服务端的数据源。接下来开启服?/p>

    service gmond start
    

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

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

    非本机客L配置需要安装服务端安装一栯行配|,q行Q非帔R烦,q里使用本机安装好的文gq行安装?使用下面的脚本进行安装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/
    

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

    sh deploy-ganglia.sh 10.1.11.2
    

    服务端的WEB配置

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

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

    安装webE序Q这里假定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的\径,文g/var/www/html/ganglia/conf.php中的RRDTOOL

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

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

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


    imxylz 2011-07-21 00:34 发表评论
    ]]>
    深入出 Java Concurrency (36): U程?part 9 q发操作异常体系http://www.dentisthealthcenter.com/xylz/archive/2011/07/12/354206.htmlimxylzimxylzTue, 12 Jul 2011 15:15:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/07/12/354206.htmlhttp://www.dentisthealthcenter.com/xylz/comments/354206.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/07/12/354206.html#Feedback3http://www.dentisthealthcenter.com/xylz/comments/commentRss/354206.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/354206.htmlq发包引入的工具cd多方法都会抛Z定的异常Q这些异常描qCd在线E池中执行时发生的例外情况,而通常q些例外需要应用程序进行捕捉和处理?/p>

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

     

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

     

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

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

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

    中断一个线EThread.interrupt()时会触发下面一U情况:

    如果U程在调?Object cȝ wait()、wait(long) ?wait(long, int) ҎQ或者该cȝ join()、join(long)、join(long, int)、sleep(long) ?sleep(long, int) Ҏq程中受阻,则其中断状态将被清除,它还收C?InterruptedException?/p>

    一个线E的中断状态描q是q样的Thread.interrupted()Q?/strong>

    试当前U程是否已经中断。线E的中断状?/em> pҎ清除。换句话_如果q箋两次调用该方法,则第二次调用返?falseQ在W一ơ调用已清除了其中断状态之后,且第二次调用验完中断状态前Q当前线E再ơ中断的情况除外Q?nbsp;

    也就是说如果到一个线E已l被中断了,那么U程的用方Q挂赗等待或者正在执行)都将应该得到一个中断异常,同时会清除异常中断状态?/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;
    }

     

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

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

     


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

    除了InterruptedException 异常我们q发C一个全新的异常java.util.concurrent.TimeoutExceptionQ此异常是用来描qCQ务执行时间超q了期望{待旉Q也许是一直没有获取到锁,也许是还没有执行完成?/p>

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

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

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

    q是因ؓ我们的提交的djava.util.concurrent.Callable在call()Ҏ中允许抛ZQ何异常,另外常规的线E执行也可能抛出一个RuntimeExceptionQ所以这里简单包装了下所有异常,当作执行q程中发生的异常ExecutionException抛出?/p>

    以上是整个异常体系Q所有ƈ发操作的异常都可以归l于上述几类?/p>

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

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

    当然一U单位的旉转换成另一U单位的旉也是非常方便的。另外还有线E的sleep/join以及对象的wait操作的便h作?/p>

     



    imxylz 2011-07-12 23:15 发表评论
    ]]>
    享受热部|的好处http://www.dentisthealthcenter.com/xylz/archive/2011/06/17/352476.htmlimxylzimxylzFri, 17 Jun 2011 01:25:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/06/17/352476.htmlhttp://www.dentisthealthcenter.com/xylz/comments/352476.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/06/17/352476.html#Feedback3http://www.dentisthealthcenter.com/xylz/comments/commentRss/352476.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/352476.html

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

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

    好吧Q我{穷Z用不P只好“自己动手/丰食”?/p>

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

     

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

    Resin 3.1+版本Q?/p>

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

    Resin 3.0-版本Q?/p>

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

    TomcatQJetty? Jboss? WebLogic? WebSphere? Maven? Eclipse? And More?

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

    Ԍ不要qQ试试吧Q?/p>

    有木有更单,更NB的热部vU籍啊?

    有的Q亲Q?/p>

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

    imxylz 2011-06-17 09:25 发表评论
    ]]>
    Crack JRebel 4.0Q无需重启JVMQ热部v解决Ҏhttp://www.dentisthealthcenter.com/xylz/archive/2011/06/12/352109.htmlimxylzimxylzSat, 11 Jun 2011 16:24:00 GMThttp://www.dentisthealthcenter.com/xylz/archive/2011/06/12/352109.htmlhttp://www.dentisthealthcenter.com/xylz/comments/352109.htmlhttp://www.dentisthealthcenter.com/xylz/archive/2011/06/12/352109.html#Feedback36http://www.dentisthealthcenter.com/xylz/comments/commentRss/352109.htmlhttp://www.dentisthealthcenter.com/xylz/services/trackbacks/352109.htmlhttp://dl.dropbox.com/u/22951342/jrebel.jar  www.zeroturnaround.com最q又接触C点WEB应用Q想到Resin服务器重启需要花Ҏ较多的时_SpringWEB服务搞得来复杂,来臃肿了Q,所以又惛_?8q那时候用JavaRebel了。一D|间不用h家居然改名ؓJavaRebel了?br />如果不熟悉的可以搜烦下JRebel/JavaRebelQ这里是官方|站Q?div style="display: inline-block; ">
    www.zeroturnaround.com?br />最q刚发布?.0版本Q功能更强大Q配|也更加单了。hg菌Ӏ?br />官方提供30天试用版Q可以先体验下再军_是否购买?br />
    看到里面的代码؜淆让我很崩溃Q没有深入研I؜淆后的运行机制。比如下面居然有两个名称相同Q参数相同,但是q回g同的静态方法,不知是如何执行的?br />public static void a(String s)?public static String a(String)Q以?br />private static void c()和private static String c()?br />猜测是在q行的时候自p行JVM指o的执行。这L代码反编译后都不知道怎么写回去,惛_崩溃Q因Z个方法居焉有地方调用了?br />


    zhangthe9 提供了一?.0的破解版Q我很好奇,咨询了下Q居然还是以前的RSA{֐法?/div>
    好吧Q翻?8q写的JavaRebel 2.0-M1的破解程序,重新生成一个license文gQ修改公钥,替换license文gQ居然运行正常。这么多q了Q签名算法和步骤居然一炚w没变Q嗯Qh家真执着Q?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 ==

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

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

    破解思\很简单,替换公钥Q用自q钥生成签名License文g?br />如果惛_蔽版本更新提C,有以下几U思\Q?br />Q?Q修改调用更新坚持的c(N有点大,因ؓh比较严重Q不Ҏ反编译)
    Q?Q修Ҏ新服务器的地址Q将http://update.zeroturnaround.com/jrebel/地址修改Q可以用二q制工具直接修改字符Ԍ比如我就update改ؓupdattQ无法解析域名就不能获取最新版本了?br />Q?Q增?Drebel.disable_update=true参数卛_。(q种Ҏ最单)?br />
    当然了,Z“保护知识产权”Q不会将破解文g攑և来,有需求的可以留言联系。(所谓的“计算机条?#8221;是允ؓ了学习、研I而进行相关逆向工程的,哈哈Q?/strike>

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

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


    imxylz 2011-06-12 00:24 发表评论
    ]]> 久久一级片
    <noframes id="395jp"><noframes id="395jp"><video id="395jp"><video id="395jp"></video></video>
    <i id="395jp"><font id="395jp"><delect id="395jp"></delect></font></i>
    <nobr id="395jp"></nobr><noframes id="395jp"><noframes id="395jp"><dl id="395jp"></dl><video id="395jp"></video><noframes id="395jp"><dl id="395jp"></dl>
    <video id="395jp"><video id="395jp"><dl id="395jp"></dl></video></video> <nobr id="395jp"><nobr id="395jp"><meter id="395jp"></meter></nobr></nobr>
    <video id="395jp"></video><nobr id="395jp"></nobr>
    <video id="395jp"></video>