leisure

          JAVA - exceed,helloworld
          隨筆 - 50, 文章 - 0, 評論 - 11, 引用 - 0
          數據加載中……

          應用啟動時,attempting to get SockIO from uninitialized pool!

          在spring配置文件中,沒有將實例名稱對應上,導致mc client無法從一個未初始化的池里獲取數據。

              <bean id="sockIOPool" class="com.danga.MemCached.SockIOPool"
                  factory-method
          ="getInstance" init-method="initialize" destroy-method="shutDown"
                  p:initConn
          ="${memcached.initConn}"
                  p:minConn
          ="${memcached.minConn}"
                  p:maxConn
          ="${memcached.maxConn}"
                  p:maintSleep
          ="${memcached.maintSleep}"
                  p:nagle
          ="${memcached.nagle}"
                  p:socketTO
          ="${memcached.socketTO}"
                  p:servers
          ="${memcached.servers}">
                  <constructor-arg value="myName"/>
              </bean>
              
              <bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">
                  <constructor-arg value="myName"/> 
                  <property name="sanitizeKeys" value="false"/>
                  <property name="compressEnable"   value="true"/>
                  <property name="compressThreshold" value="1024"/>
              </bean>

          注意<constructor-arg value="myName"/> 中的myName要保持一致。

          posted @ 2012-02-17 14:44 leisure 閱讀(3464) | 評論 (1)編輯 收藏

          eclipse安裝svn客戶端

          下載相應的插件版本
          把解壓的內容放置eclipse\dropins\svn\目錄下(svn目錄不存在則創建)
          完成后,重啟eclipse,重啟完后,提示安裝svn connector,選擇一個安裝即可,安裝完后,再一次重啟。
          window - show view - other - svn 下即可以看到svn控制視圖

          posted @ 2012-01-25 10:59 leisure 閱讀(309) | 評論 (0)編輯 收藏

          hello,spring3

          spring很早就更新了3.0版本,可是由于項目要求穩定,卻一直沒有使用到,最近有個新項目,打算采用spring3了。

          項目整個結構如下:


           1 <?xml version="1.0" encoding="UTF-8"?>
           2 <beans xmlns="http://www.springframework.org/schema/beans"
           3      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           4      xmlns:p="http://www.springframework.org/schema/p"
           5      xsi:schemaLocation="http://www.springframework.org/schema/beans
           6      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
           7      
           8     <bean id="dao" class="Dao"/>
           9     
          10 </beans>

          1 
          2 public class Dao {
          3     public void find() {
          4         System.out.println("dao: find()");
          5     }
          6 }
          7 

           1 import org.springframework.context.ApplicationContext;
           2 import org.springframework.context.support.ClassPathXmlApplicationContext;
           3 
           4 public class Client {
           5 
           6     public static void main(String[] args) {
           7         ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
           8         Dao dao = context.getBean(Dao.class);
           9         dao.find();
          10     }
          11 }
          12 

          posted @ 2011-12-29 16:02 leisure 閱讀(211) | 評論 (0)編輯 收藏

          java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

          獲取泛型參數的類型
                  
          Class<TentityClass = (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];

          出現:
          java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

          使用以下工具類方法獲取~
           1 package cn.pconline.prolib.util;
           2 import java.lang.reflect.ParameterizedType;  
           3 import java.lang.reflect.Type;  
           4   
           5 public class GenericsUtils {  
           6     /**   
           7      * 通過反射,獲得定義Class時聲明的父類的范型參數的類型.   
           8      * 如public BookManager extends GenricManager<Book>   
           9      *   
          10      * @param clazz The class to introspect   
          11      * @return the first generic declaration, or <code>Object.class</code> if cannot be determined   
          12      */  
          13     public static Class getSuperClassGenricType(Class clazz) {  
          14         return getSuperClassGenricType(clazz, 0);  
          15     }  
          16   
          17     /**   
          18      * 通過反射,獲得定義Class時聲明的父類的范型參數的類型.   
          19      * 如public BookManager extends GenricManager<Book>   
          20      *   
          21      * @param clazz clazz The class to introspect   
          22      * @param index the Index of the generic ddeclaration,start from 0.   
          23      */  
          24     public static Class getSuperClassGenricType(Class clazz, int index) throws IndexOutOfBoundsException {  
          25   
          26         Type genType = clazz.getGenericSuperclass();  
          27   
          28         if (!(genType instanceof ParameterizedType)) {  
          29             return Object.class;  
          30         }  
          31   
          32         Type[] params = ((ParameterizedType) genType).getActualTypeArguments();  
          33   
          34         if (index >= params.length || index < 0) {  
          35             return Object.class;  
          36         }  
          37         if (!(params[index] instanceof Class)) {  
          38             return Object.class;  
          39         }  
          40         return (Class) params[index];  
          41     }  
          42 }  

                  
          Class<TentityClass = GenericsUtils.getSuperClassGenricType(BasicService.class0);

          posted @ 2011-12-26 14:37 leisure 閱讀(17896) | 評論 (4)編輯 收藏

          淺淡Java代理模式之秘書MM

          代理對象一般定義了一個與目標對象相似或相近的行為。代理對象負責對真實模塊調用,這使得調用者與被調用者之間建立了一個隔離帶。
          場景示例說明:老總說話都是很精簡,每次發布一個消息時,總是先將簡要內容交給秘書MM,秘書MM經過一番美化后,把消息公布出來。

          設老總=Boss,秘書MM=MMProxy

          于是簡單的代理就有
          1 public class Boss {
          2     public void anounce(String content) {
          3         System.out.println(content);
          4     }
          5 }

          1 public class MMProxy {
          2     public void anounce(String content) {
          3         System.out.print("boss: 大家請注意了!");
          4         new Boss().anounce(content);
          5     }
          6 }

          new MMProxy().anounce("我請大家吃飯。");

          結果出來的是:
          boss: 大家請注意了!我請大家吃飯。

          通過上面發現,這種代理比較呆板,比如說,Boss口渴了,又得重新寫一個代理方法,這個時候,可以使用動態代理來進行:

          添加一個接口IBoss
          1 public interface IBoss {
          2     public void anounce(String content);
          3     public void drink();
          4 }

          修改Boss
          1 public class Boss implements IBoss {
          2     public void anounce(String content) {
          3         System.out.println(content);
          4     }
          5 
          6     public void drink() {
          7         System.out.println("boss: 拿起杯子,喝水");
          8     }
          9 }

          這時秘書MM變為
           1 import java.lang.reflect.InvocationHandler;
           2 import java.lang.reflect.Method;
           3 
           4 public class MMProxy implements InvocationHandler {
           5 
           6     private Object obj;
           7 
           8     public MMProxy(Object obj) {
           9         this.obj = obj;
          10     }
          11 
          12     public static Object newInstance(Object obj) {
          13         return java.lang.reflect.Proxy.newProxyInstance(
          14             obj.getClass().getClassLoader(),
          15             obj.getClass().getInterfaces(),
          16             new MMProxy(obj));
          17     }
          18     
          19     @Override
          20     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
          21         if("drink".equals(method.getName())) {
          22             System.out.println("秘書MM: 看到boss想喝水了,于是 把水倒進boss的杯子里。");
          23         } else if("anounce".equals(method.getName())) {
          24             System.out.print("boss: 大家請注意!");
          25         }
          26         method.invoke(obj, args);
          27         return null;
          28     }
          29 }

                  IBoss boss = (IBoss) MMProxy.newInstance(new Boss());
                  boss.anounce(
          "我請大家吃飯。");
                  boss.drink();

          boss: 大家請注意!我請大家吃飯。
          秘書MM: 看到boss想喝水了,于是 把水倒進boss的杯子里。
          boss: 拿起杯子,喝水

          現在發現了吧,秘書MM真是服務周到呀。

          posted @ 2011-12-09 09:54 leisure 閱讀(256) | 評論 (0)編輯 收藏

          [nginx]post數據莫名奇妙丟失事件

          昨天快下班的時候,有位同事遇到post數據接收不到的問題

          首先網絡架構是:
               nginx1
                 |  rewrite
               nginx2
                 |  pass
               resin1

          nginx1是在192.168.1.1上
          nginx2跟resin1是在192.168.1.2上

          首先訪問nginx1,由nginx1 rewrite到nginx2,nginx2直接pass到resin1,整個過程是POST形式。至于
          為什么要用兩層nginx,這當然是有原因的了:-)

          于是乎,快速制定了幾個測試案例:
          1,兩種訪問方式:GET,POST
             GET URL帶參數,沒有問題。
             POST 有問題。
             讓網絡同事檢查,處理這個location并沒有做什么特殊的POST處理。——!
          2,訪問nginx1時,直接pass到resin1,跳過nginx2
             問題依舊。
          3,去掉nginx1,訪問nginx2,直接pass到resin1
             有數據的。
          4,直接訪問resin1
             是有數據的。

          到這里,我感到很奇怪,為啥,為啥nginx1傳遞不了post數據呀,而nginx2可以,問題肯定出現在nginx1的配置上!~經過一番斗爭后,終于找到問題關鍵
          nginx1中,配置了一個全的post處理
          if($request_method = POST) {
             rewrite .* /post.php last;
          }
          最后,只能大眼望細眼,汗一滴。

          posted @ 2011-11-25 12:07 leisure 閱讀(5932) | 評論 (0)編輯 收藏

          反射判斷成員變量是否靜態,并獲得其靜態成員的值

                  Field[] fields = cls.getDeclaredFields();
                  Field field 
          = fields[0];
                  
          boolean isStatic = Modifier.isStatic(field.getModifiers());
                  if(isStatic) {
                      System.out.println(
          field.get(null).toString());
                  }

          posted @ 2011-11-23 17:06 leisure 閱讀(7100) | 評論 (0)編輯 收藏

          npm ERR! Error: socket hang up

          when i use npm to install express, it goes this message:

          npm info it worked if it ends with ok
          npm info using npm@1.0.106
          npm info using node@v0.6.2
          npm info addNamed [ 'express', '' ]
          npm ERR! Error: socket hang up
          npm ERR! at createHangUpError (http.js:1092:15)
          npm ERR! at CleartextStream. (http.js:1175:27)
          npm ERR! at CleartextStream.emit (events.js:88:20)
          npm ERR! at Array.0 (tls.js:731:22)
          npm ERR! at EventEmitter._tickCallback (node.js:192:40)
          npm ERR! Report this entire log at:
          npm ERR! http://github.com/isaacs/npm/issues
          npm ERR! or email it to:
          npm ERR! npm-@googlegroups.com
          npm ERR! 
          npm ERR! System Linux 3.0.0-12-generic
          npm ERR! command "node" "/usr/local/bin/npm" "install" 
          "express" "-d"
          npm ERR! cwd /home/leisure/software/node-v0.6.2
          npm ERR! node -v v0.6.2
          npm ERR! npm -v 1.0.106
          npm ERR! code ECONNRESET
          npm ERR! 
          npm ERR! Additional logging details can be found in:
          npm ERR! /home/leisure/software/node-v0.6.2/npm-
          debug.log
          npm 

          it sounds the https_proxy is broken.
          so try to use http registry to solve it:
          npm config set registry http://registry.npmjs.org/

          posted @ 2011-11-23 15:11 leisure 閱讀(3328) | 評論 (1)編輯 收藏

          MYSQL Error Code: 1093 You can't specify target table 'x' for update in FROM clause

          當子查詢作為條件,執行delete跟update操作時,會出現:
          Error Code: 1093 You can't specify target table 'x' for update in FROM clause

          作一個簡單的示例:
          CREATE TABLE tbl_a(
          id 
          INT,
          NAME 
          VARCHAR(50)
          );

          INSERT INTO tbl_a VALUES(1'leisure');
          INSERT INTO tbl_a VALUES(2'leisure2');

          SELECT * FROM tbl_a;

          執行更新操作
          UPDATE tbl_a 
              
          SET id = (
                  
          SELECT id FROM tbl_a 
                  
          WHERE NAME = 'leisure2'
              ) 
          WHERE NAME = 'leisure';

          這時,如愿見到我們標題上的錯誤,解決方法如下(橙色字體系關鍵):
          UPDATE tbl_a 
              
          SET id = (
                  
          SELECT id FROM (
                      
          SELECT * FROM tbl_a WHERE NAME = 'leisure2'
                  ) xx
              )
          WHERE NAME = 'leisure';

          posted @ 2011-11-22 09:58 leisure 閱讀(3546) | 評論 (1)編輯 收藏

          解決IE下location.href丟失refer信息

          相信有很多朋友,用javascript做一些跳轉時,往往發現refer信息丟失了。為了解決該問題,在IE下,模擬一下點擊事件即可!

          function jumpTo (url) {
              var isIE 
          = !-[1,];
              if (isIE) {
                  var link 
          = document.createElement("a");
                  link.href 
          = url;
                  link.style.display 
          = 'none';
                  document.body.appendChild(link);
                  link.click();
              } 
          else {
                  window.location.href 
          = url;
              }
          }

          posted @ 2011-11-17 16:54 leisure 閱讀(1062) | 評論 (0)編輯 收藏

          僅列出標題
          共5頁: 上一頁 1 2 3 4 5 下一頁 
          主站蜘蛛池模板: 池州市| 襄汾县| 兴安盟| 墨脱县| 利川市| 新田县| 泾源县| 伊吾县| 田阳县| 石渠县| 新化县| 原阳县| 抚州市| 东港市| 西青区| 西乡县| 河池市| 涞源县| 加查县| 嘉定区| 阿荣旗| 乐陵市| 花莲市| 天台县| 三台县| 宁南县| 临西县| 多伦县| 兴国县| 濮阳县| 柯坪县| 达拉特旗| 定结县| 龙陵县| 蒲江县| 桐梓县| 咸丰县| 巴彦淖尔市| 江北区| 嘉善县| 杭锦后旗|