static AbstractApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:context.xml"); static boolean isDo = true; public static void main(String[] args) throws InterruptedException { for(int i=0; i<10; i++){ new Producer().start(); } ctx.registerShutdownHook(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { isDo = false; Thread.sleep(1000); //ctx.close(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(ctx.getBean("messageListener", TestAmqSpringMessageListener.class).getCounter()); } }); }
Month: 四月 2013
mysql 不能使用 localhost 或 127.0.0.1 访问
问题的原因可能是:
1. 没有找对 mysql.sock 文件路径,mysql 命令一般默认(/var/lib/mysql/mysql.sock),php 一般默认(/tmp/mysql.sock) – (localhost)
2. my.cnf 开启了 skip-networkig – (127.0.0.1)
利用Jconsole远程监控JVM
nohup java -Djava.rmi.server.hostname=172.16.0.201 -Dcom.sun.management.jmxremote.port=30591 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar xk.jar &
php 复制对象
private function makeStr($str, $dt){ $tmp_dt = clone $dt; $tmp_dt->modify('+1 day'); $str = $tmp_dt->format('m/d').'-'.$str; unset($tmp_dt); return $str; }
1、PHP5对象复制是采用引用的方式;
2、如果不采用引用方式,则需要在复制对象时加关键字 clone;
3、如果在复制的过程中,同时要变更某些属性,则增加函数 _clone();