Damn slow

Discard this blog, move and continue with http://fujohnwang.blogspot.com/,  墙外…

 

 

趣事一二

  • 陪少川去买奇瑞, 偶然间却发现销售小伙儿开的却是昊瑞;
  • 提车上高架, 走错了路口, 绕了很长一大圈发现不对, 就下桥掉头往回绕;走过一个加油站才猛然想起来提完车忘记加油了,然后又掉头,掉头横在路中央的时候, 惹来让路的大客车司机鄙夷的笑。
  • 都说狗娘养的,狗娘养的, 今天家里的狗爆了窝小狗才突然感觉到, 其实狗娘也挺不容易的,孤零零的抚养一堆小狗,当初下种的那个早不知道哪里去了…
  • 今天又tmd碰上同样的骗子, 告诉我汽车退税, 本来想逗逗她,没想到她最后留了一手, 让我重新报一遍给我留的所谓的国税局的电话, 我当然报不上来咯, 她就自己挂掉了,哈,看来是长记性了。
  • It’s a looooong day

    今天部门出去活动, 可是大清早的就电闪雷鸣的, 暴雨啊, 本来不想出去了, 可想想没有人通知我取消,我只好出门。
    开车刚出小区门口转到滨康路, 妈呀, 这水, 可已经转到这条路上来了,也不好掉头,只好踩油门打算冲过去,一进水就感觉不对,踩油门都没太大反应,不管怎么说,还是闯到了下一个路口,可是放眼望去,还是一滩汪洋, 我心想, 反正出来不远, 直接掉头回去算了, 刚掉过头来却发现一辆宝马已经横在路中,熄火跟儿p了。妈呀, 它挡着我咋过啊, 边上公交车站那快儿到是空着,可估计水更深, 不敢走啊。 回想来回想去, 得,硬着头皮闯吧! 还亏小S底盘高, 最终还是成功突围。 心想这样的场景一定的纪念一下, 靠边停车, 拿出相机咔嚓了寂以做纪念


    从安全地带出来, 没回去,往公司开(原来说要我到公司接几个人), 转到公司边上的春波路, 发现路口这车不地道, 可又不知道咋回事, 等自己转进去才发现,md,又是一片汪洋啊!
    有个哥们从水里淌出来还比划有的地方到他腿弯那里…

    再一次庆幸小S底盘高,我水里掉头又爬出来了…

    掉头出来,到公司北边的滨兴路, 这条路还好,可想转到公司正门停车才发现,公司正面那条路也淹了, 许多车都开到马路牙子上停, 我看没地方, 掉头在公司对面找了个地方停的车。

    等人来了,我想想还是算了吧,大家打车吧,广播里说江南大道也淹了, 而那里又是必经之路,我这刚摸车没多久的菜鸟,还是算了吧。

    打车路上因为江南大道部分路段淹得厉害,所以堵车严重, 耗了很长时间才跑到龙井村那边。

    中午吃的“绿茶”, 有几个菜还不错,像“农夫炖鱼”, “面包诱惑”, 不过等第二盘“农夫炖鱼”上来后吃了几口发现, 好像味道不如一开始那盘好,哈哈,不知道是不是吃饱了, 估计是早上没吃饭, 吃啥都香。

    吃完饭,天晴了, 三辆车回滨江先让我取车(否则,晚上活动完后滨江区这边几个人回家就成问题了), 然后去万象城。有三桥捷径不走, maomao前面带头走四桥高架。
    MD, 过了钱塘江就开始堵车, 还熄火了几次。 最戏剧性的是, 这里我出车祸了。 当然,没那么严重,不过也算第一次车祸吧!

    我沿着高架走, 后面一个彪子从两个车中间蹿到我前面然后直接右拐别我, 反正我是还不知道咋回事那,就发现两个车亲密上了。 那彪子没停车,马上慢慢绕到前面停车(后来才想明白,这b是想推卸责任), 下车, 问这b怎么开车的, 第一次车祸,我也不知道该怎么办, 反正看他的沃尔沃车门已经瘪进去很大一块, 回头看看我小S, 只是车轮挡泥板的塑料蹭了些刮痕,所以也没想怎么地, 然后这厮说走吧,跟他去修理厂,帮我弄一下, 呵呵,我上车也没想要跟他去修理厂, 前面同事车还等着那, 谁tmd跟他耗啊。 没一会,这b就东蹿西攒的消失了。 估计遇到我这样的,这b一定心里暗爽,骂我sb之类的吧。回头到了集合的地方, 说起这事儿, BT说这事儿应该最少敲他500, 靠,我要不是第一次啥也不懂, 当然不会放过他啦, 这次就算了吧, 当交学费了,唉,说起来,这不到半个月,我的小S已经有2次刮擦了…

    晚上吃的一茶一座,因为外婆家实在排队等不起, 吃完饭看万象城里滑冰场里一群人滑冰, 又遇到一个小子, 但我怎么也想不明白,他跟我得色什么, 我又不是女的, 能引起他荷尔蒙分泌旺盛。只见这小子向着我猛冲, 然后想急刹, 得,吧唧, 狠狠的摔在地上, 之后灰溜溜的爬起来,滑走了.

    差不多到点了, 见票入场, 看iMAX版本的“盗梦空间”, mmd, imax就是爽啊, 这电影的剧情也爽,呵呵,总之, 这电影看的值,不过要是自己掏钱,估计就不值了,哈哈, 110大元.

    看完送他们4个人回滨江,几乎是挨个送到家, “天南海北”啊,我这车夫做的真tmd辛苦, 本来送完糖糖我左转穿过一个桥就可以到家了,可是刚转过去却发现牌子,说让水淹,不能走, 哎, 绕吧~, 掉头, 跑老远上高架,再下高架, 折腾了一圈才到住处,已经11点多了, 一个字, 累~

    行车记录

    本来嘛,学完车4,5年没有再摸车了,这倒好,怕什么来什么, 一上来就碰上了几个艰巨的任务…

    1-高架惊魂

        周五去城北车管所上牌子, 上次把车开回来已经让钱磊旷工帮我开回来了,这次怎么说也不能再麻烦他了, 所以,赶鸭子上架,自己来吧!本来以为11点左右高架桥上车能少点儿, 可没想到的是,过了4桥之后没多久就开始堵,还好, 去的时候不管熄火多少次,总算是安全到达目的地石祥路390号祥通铃木4S店。
        本来预计3:30就差不多能办完了,可没想到人太多, 折腾到5点多, 而且办完后还回4S店给他复印一下资料。 得, 看着4S店外严密的车流,我有点儿彻底崩溃了的感觉, 你要知道,那一块儿什么大车都有, 而且, 下了高架就一条路, 我想掉都并道,那简直了-impossible的感觉。
        4S点出来到我掉头上高架的地方,总共也就几十步路的样子,我tmd在那里却浪费掉10-20分钟, 最搞笑的是,我并完道却发现内道有车祸,mmd, 玩死啊。再往外并, 有个哥们还回头看我车有没有蹭到他的车,哈哈, 那种情况下, 不蹭我觉得都是奇迹。
        好不容易从桥下的鬼门关出来, 一上高架,好嘛,比我来的时候还热闹, 一上桥就开始龟爬了。期间熄火无数, 这还好说,我怕蹭了前面的车,所以预留了1-2个车的距离,mmd,有些sb还真的往里插, 真想问候一下他们的老娘。
       
    2- 比出中指

        周六领俩小徒弟去垃圾街(杭州滨江区的小吃一条街), 加完油,从江边绕, 在红灯之后右转熄火, 我后面的车就开始鸣笛,鸣笛就鸣笛吧,我知道挡了你, 可我发现后面这开车的好像不正常, 按理说,这事儿过就过去了,而且我车也没牌子,后面车也应该知道是新手之类吧, 可事儿还没完, 我都开出来很远了,后面车居然跟上来又跟我鸣笛,md,我直接对其比出中指。我很想做, 却一直没几会做的事情,遇到这样的,我就不客气了。(后面徒弟还让我文明点,哈)

    3- 忏悔碰人

        垃圾街人很多, 开进去才发现没有停车的地方,只好找路出来, 鸣笛人家都不让该怎么走还怎么走,你一点儿脾气没有。都快到路口了,居然碰了一个姐们,我本来那还有要道歉的意思,可他男朋友居然拍我车子, 得,我还是闪人吧! 只对当事人忏悔, 对拍我车子的, …

    开车看来真的是对脾气不好…

    (不过, 短时间内经历了这么艰巨的车况和路况,我还是没想到能make it)

    徒儿串讲的PPT

    拍荷花2

    另一个兄弟的作品, 配备了长焦镜头

    当然啦, 同样是长焦镜头,也可以用作其他用途, 简直就是人间凶器嘛~

    在电影院乘凉的时候, 隔着老远, 居然都把人物的表情抓拍的如此…

    拍荷花

    可能带我那个长焦的相机去拍,效果要更好一些, 单反只配了18-55mm标准镜头, 变焦能力有限,推不到荷花跟前, 所以,拍不出微距的效果, 姑且讲究着看吧!

    下面, 请大家欣赏周围的摄影人,呵呵, 长枪大炮, 看着很是相形见绌,哈

    其他的一些闲拍…

    Java Daemon Control

    Java Daemon Control

    王福强(Darren.Wang)

    <fujohnwang@gmail.com>

    2010-07-27


    As to desktop or normal Java applications, we can easily know when we
    should shutdown the application or not, because users have explicit ways
    to do
    this, for example,
    for a Swing Application, usually a "CLOSE" menu or tool-bar item will
    be available, or directly click the "X" icon on the left/right top of
    the window.
    But for a Java application that will be run as a server process(which
    don't need interactive behavior), what we do?

    1. Old Days Solutions

    Directly
    kill -9
    ? Of course, that's a way, but that's too brutal.

    A Java process that will be run as a server process usually will be sent to OS's background to run, that's called
    daemon
    on Unix and
    service
    on Windows.
    A Simple way to control the life-cycle of a Java daemon is to start a loop and wait for user input, like this:

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String line = null;
    do {
    line = reader.readLine();
    if (line != null && line.equals("quit")) {
    break; // and exit gracefully
    }
    }
    while (true);

    // clean up and exit

    This solution is better than just start an infinite loop and do
    nothing, because the latter solution will occupy all of your CPU's
    power(I have seen such a
    stupid solution and it does exist). But this is still not a best one,
    although users can interactive with it, the process itself have no way
    to notify the
    process to exit. That's, you can control it from outside, but can't
    do it from inside.

    Another mostly used solution is, start a TCP server socket and listen
    control requests, when termination control request is received, a loop
    based on
    control
    flag will break and exit. This is similar to above solution, just
    with another communication channel.
    [1]

    A common pattern for both solution can be found,that's, set up a control flag to start a loop with,
    and then wait for other channels to change the control
    flag. This can be formulated as:

    boolean running = true;

    while(running)
    {
    // do Sth.
    }
    // exit

    As to how to change the control flag, there are two solutions presented, can you find more?

    2. Alternatives Available Today

    Old Days Solutions
    have their pros and cons, today more solutions are available for us.

    The first one is
    Jakarta Commons Daemon
    .
    It provides a Java daemon solution with native Jsvc and Procrun support.

    The second and third are
    Java Service Wrapper
    and
    yajsw
    ,
    The former is a commerce solution now, and the latter is an open
    source one which has some works based on the former(there is a
    possibility that I
    misunderstand its introduction).

    Other Solutions are
    Akuma
    , Start-Stop-Daemon, or
    Classword
    , but I don't get patience to read their document. If you are interested in them, follow the links I provide or google them.

    3. My Choice

    I choose to combine shell and
    sun.misc.Signal
    and
    sun.misc.SignalHandler
    to achieve Java daemon, because they are much simpler to me to understand them and use them.
    The
    Shell will take care of running-in-background stuff:

    #!/bin/sh
    java -cp your_class_path com.domain.main_class <&- &
    pid=$!
    echo ${pid} > mydaemon.pid

    And
    sun.misc.Signal
    and
    sun.misc.SignalHandler
    will take care of controlling the life-cycle of the program.

    About
    sun.misc.Signal
    and
    sun.misc.SignalHandler
    , you can find more information at
    参考文档
    , here I just simply introduce how to use them together to achieve
    asynchronous communication between processes or just internally in a
    same process.

    The concept of
    sun.misc.Signal
    and
    sun.misc.SignalHandler
    is simple:

    • Signal is the signal that u will send to SignalHandler to process,
      so you can create a Signal just like instantiate a simple value object:

      Signal sig = new Signal("USR1");

      The signal names you pass to
      Signal
      conform a pattern, that's,
      remove the prefix "SIG" from the name of the standard signals that's used by JVM
      [2]
      . For example, if you want to send
      SIGINT
      , then you create
      Signal
      instance with name of
      INT
      ;
      If you want to send
      SIGTERM
      , you create
      Signal
      instance with name of
      TERM
      :

      Signal interactiveSignal = new Signal("INT");
      Signal terminationSignal = new Signal("TERM");

      Fucking Simple, right?

      After you have a Signal, you can send it out by using
      Signal
      class's
      raise
      method:

      Signal.raise(sig); 
      Signal.raise(interactiveSignal);
      Signal.raise(terminationSignal);

    • As the name indicates,
      SignalHandler
      will take the responsibility of handling the
      Signal
      s.

      You implements your own signal handlers by implementing the
      SignalHandler
      interface. It has only one method:

      public class MySigHandler implements SignalHandler {

      public void handle(Signal sig) {
      // ...
      }
      }

      It's fucking simple too.

    After you get both
    Signal
    and
    SignalHandler
    of your own, you should link them together to make it work. This is by
    Signal
    class's static method
    handle
    :

    MySigHandler sigHandler = new MySigHandler();
    Signal.handle(sig, sigHandler);
    Signal.handle(interactiveSignal, sigHandler);
    Signal.handle(terminationSignal, sigHandler);

    Now as long as you add them to your java programs and send proper signals to it, the pairs of
    Signal
    and
    SignalHandler
    will work for you.

    You have 2 ways to send signals to your program's process:

    1. Use Signal.raise() internally. 
      This can help to coordinate application's internal state and help
      to control the life-cycle internally.
      For example, as long as internal worker
      thread dies, it can send out a signal, when signal hander finds
      that all other the worker threads die, it can change the control flag of
      the whole
      process and terminate it gracefully.

    2. Send Signal from other processes. 
      directly send out supported OS signal via shell scripts:

      kill -s SIGUSR1 <pid of the process>

      combining the pid you get in before shell, this works perfectly.

    The only cons to use
    Signal
    and
    SignalHandler
    is, they are both restricted API which are not guaranteed.

    Tip

    If you find erros below in Eclipse:

    Access restriction: The constructor Signal(String) is not accessible due to restriction on required library
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar ErosaSignalHandler.java
    /erosa2.0.1_ga/src/main/java/com/alibaba/erosa/common/ctrl line 15 Java Problem

    Then it's Eclipse's problem, not the OS you use.

    To fix it, go to Preference -> Java -> Compiler -> Errors/Warnings,
    find Deprecated and restricted API section, then find Forbidden reference(access rules): item, change its value from Error to Warning,
    then it's done!

    A. 参考文档


    [1]
    To use this solution, you'd better add authentication to your
    control service so that others with malicious purpose will not hurt you.

    [2]
    you can find these standard signals at
    参考文档
    .

    Thank you, My dear fella

         Only the people who care about you and know well about the situations you are gonna encounter will tell you the truth and help you to stay away from the improper situations. I am so glad that I have such kind of best friend.
        Sometimes, walking alone for a long, long time will make you loss the right direction and the right path you had set before. But with such kind of friends, they will alert you when you try to break your own principle and go wrong direction.
        I will step on the brake and adjust the wheel to go on with my own path and the path I deem right.

    road map

    Follow

    Get every new post delivered to your Inbox.