2015年1月

java 多线程 并发 之 CyclicBarrier

首先, 这是一篇很好的教程: CyclicBarrier的用法

需要注意的其他点:

  1. 即使你不设置超时时间, 系统默认有个超时时间
  2. 当所有线程到达Barrier之后, 这个CyclicBarrier 可以被下次使用
  3. 并发结果是要么全部成功, 要么全部失败, 所以要对await() 方法捕获异常, 并且尝试恢复;

busybox sendmail 例子

  1. 首先创建一个纯文本, 写入一下内容:

Subject: Restart due to high load
CC:tian@gmail.com
To:admin@tianxiaohui.com
From:test@tianxiaohui.com

Restart due to high load on router

  1. 发送email的命令

cat var/test/routerRestartMail.txt | sendmail -S"smtp.163.com" -au"我的163邮箱用户名" -ap"163邮箱密码" -f"发送者邮箱名@163.com"

  1. sendmail 的详细说明文档:

root@home:/opt/var/eric# sendmail
BusyBox v1.18.4 (2013-05-26 18:44:50 CST) multi-call binary.

Usage: sendmail [OPTIONS] [RECIPIENT_EMAIL]...

Read email from stdin and send it

Standard options:

    -t              Read additional recipients from message body
    -f sender       Sender (required)
    -o options      Various options. -oi implied, others are ignored
    -i              -oi synonym. implied and ignored

Busybox specific options:

    -w seconds      Network timeout
    -H 'PROG ARGS'  Run connection helper
                    Examples:
                    -H 'exec openssl s_client -quiet -tls1 -starttls smtp
                            -connect smtp.gmail.com:25' <email.txt
                            [4<username_and_passwd.txt | -au<username> -ap<password>]
                    -H 'exec openssl s_client -quiet -tls1
                            -connect smtp.gmail.com:465' <email.txt
                            [4<username_and_passwd.txt | -au<username> -ap<password>]
    -S server[:port] Server
    -au<username>   Username for AUTH LOGIN
    -ap<password>   Password for AUTH LOGIN
    -am<method>     Authentication method. Ignored. LOGIN is implied

Other options are silently ignored; -oi -t is implied

home.tianxiaohui.com 更换新的免费证书

之前一直使用的是startSSL的证书, 这个证书是免费的, 虽然startSSL 宣称它的证书浏览器都认, 不过发现在有些浏览器上面, 还是不认这个, 我的Android 手机上面就不认, 公司里面的IE 浏览器也不认, 所以就投靠了新的免费证书: 沃通.

沃通的免费证书很容易申请, 申请之后几分钟就可以下载了. 并且不需要注册.

替换: 因为之前已经设置过证书, 只要替换一把, 全都可以用.

Java 引用 Reference 和 C 的指针 Pointer

指针 (Pointer): 指向内存的一个地址, 在C 里面, 可以对指针进行加减运算, 其实是内存地址的向前或向后, 它比较灵活, 也可以对俩个指针直接进行对比. 在内存里面, 直接对这个指针做加减运算, 就又可能到了一块无法预知的地址.

引用 (Reference): 较指针而言, 引用可以认为是一个抽象的指针, 在JVM的具体实现里面, 有的JVM可能指向的就是一块内存地址, 当然你不能对引用进行加减运算. 有的JVM里面的引用可能是只想的一个Map, 这个Map里面的值再具体指向内存的一块空间.