云自無心水自閑

          天平山上白云泉,云自無心水自閑。何必奔沖山下去,更添波浪向人間!
          posts - 288, comments - 524, trackbacks - 0, articles - 6
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          最近在開發中遇到一個問題,就是如何判斷遠端服務器是否已經斷開連接,如果斷開那么需要重新連接。 

          首先想到socket類的方法isClosed()、isConnected()、isInputStreamShutdown()、isOutputStreamShutdown()等,但經過試驗并查看相關文檔,這些方法都是本地端的狀態,無法判斷遠端是否已經斷開連接。 

          然后想到是否可以通過OutputStream發送一段測試數據,如果發送失敗就表示遠端已經斷開連接,類似ping,但是這樣會影響到正常的輸出數據,遠端無法把正常數據和測試數據分開。 

          最后又回到socket類,發現有一個方法sendUrgentData,查看文檔后得知它會往輸出流發送一個字節的數據,只要對方Socket的SO_OOBINLINE屬性沒有打開,就會自動舍棄這個字節,而SO_OOBINLINE屬性默認情況下就是關閉的,太好了,正是我需要的! 

          于是,下面一段代碼就可以判斷遠端是否斷開了連接: 

          Java代碼  收藏代碼
          1. try{  
          2.       socket.sendUrgentData(0xFF);  
          3. }catch(Exception ex){  
          4.       reconnect();  
          5. }  

          posted @ 2013-08-15 20:09 云自無心水自閑 閱讀(2695) | 評論 (0)編輯 收藏

          有一個WEB應用,使用了AJAX框架,所有頁面的展示都是從AJAX的函數中進行的。
          在這種情況,有一個很簡單的方法來下載一個文件:
          window.location="download.action?para1=value1...."

          posted @ 2013-08-14 08:13 云自無心水自閑 閱讀(378) | 評論 (0)編輯 收藏

          run in the mysql command line client next sequence of queries:

          USE mysq;
          SHOW TABLE STATUS;
          SHOW INDEX FROM `columns_priv`;
          DESCRIBE `columns_priv`;
          SHOW INDEX FROM `db`;
          DESCRIBE `db`;

          describe `column_priv`; ERROR `(HY000): Can't create/write to file 'c:\windows\Temp\#sql_7a4_0.MYD (Errcode: 2)

          Delete the file #sql_7a4_0.MYD if exists

          posted @ 2013-03-06 08:52 云自無心水自閑 閱讀(912) | 評論 (2)編輯 收藏

          在apache dbutil中,給數據列起別名有時候不起作用。這時候,需要在連接字符串中添加一個參數:

          useOldAliasMetadataBehavior=true";

          posted @ 2012-11-18 20:23 云自無心水自閑 閱讀(439) | 評論 (0)編輯 收藏

          Mysql replication error 1201
          On a fine happy morning I am greeted with an alert that slave is not running. Running start slave yields this:
          ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
          Enabling the log yielded nothing. Googling yielded This Page that helped me a lot, but I didn't have to do quite as much work all over again. Here is what I did.
          First, I saved my "SHOW SLAVE STATUS\G" output:
          ************************** 1. row **************************
                       Slave_IO_State:
                          Master_Host: 127.0.0.1
                          Master_User: replication
                          Master_Port: 3307
                        Connect_Retry: 60
                      Master_Log_File: mysqld-bin.000401
                  Read_Master_Log_Pos: 98
                       Relay_Log_File: mysqld-relay-bin.006135
                        Relay_Log_Pos: 242
                Relay_Master_Log_File: mysqld-bin.000401
                     Slave_IO_Running: No
                    Slave_SQL_Running: No
                      Replicate_Do_DB:
                  Replicate_Ignore_DB:
                   Replicate_Do_Table:
               Replicate_Ignore_Table:
              Replicate_Wild_Do_Table:
          Replicate_Wild_Ignore_Table:
                           Last_Errno: 0
                           Last_Error:
                         Skip_Counter: 0
                  Exec_Master_Log_Pos: 98
                      Relay_Log_Space: 0
                      Until_Condition: None
                       Until_Log_File:
                        Until_Log_Pos: 0
                   Master_SSL_Allowed: No
                   Master_SSL_CA_File:
                   Master_SSL_CA_Path:
                      Master_SSL_Cert:
                    Master_SSL_Cipher:
                       Master_SSL_Key:
                Seconds_Behind_Master: NULL
          1 row in set (0.00 sec)
          STOP SLAVE; RESET SLAVE;
          mysql> CHANGE MASTER TO MASTER_LOG_POS=98 , MASTER_LOG_FILE = 'mysqld-bin.000401';
          Query OK, 0 rows affected (0.04 sec)
          mysql> start slave;
          Query OK, 0 rows affected (0.00 sec)
              
          The position comes from the output I saved before
          It's working fine again. Still don't know what caused this - possibly random remote server power cycling...

          posted @ 2012-11-18 20:23 云自無心水自閑 閱讀(617) | 評論 (0)編輯 收藏

          picky挑剔的;
          quick-tempered容易發脾氣的;
          rude粗魯無禮的;
          scatter-brained 記性不好的;
          slapdash粗心大意的;
          sly狡猾的;
          spiteful懷恨在心的;
          thoughtless草率的;
          fussy挑剔的;
          manic狂躁的;
          manipulative喜歡指使別人的;
          moody情緒化的

          posted @ 2012-10-20 20:51 云自無心水自閑 閱讀(346) | 評論 (0)編輯 收藏



           package org.springside.examples.miniweb.dao.account;
          import java.util.List;
          import javax.persistence.EntityManager;
          import javax.persistence.PersistenceContext;
          import org.springframework.stereotype.Component;
          import org.springside.examples.miniweb.entity.account.Group;
          import org.springside.examples.miniweb.entity.account.User;
          /**
           * GroupDao的擴展行為實現類.
           */
          @Component
          public class GroupDaoImpl implements GroupDaoCustom {
          private static final String QUERY_USER_BY_GROUPID = "select u from User u left join u.groupList g where g.id=?";
          @PersistenceContext
          private EntityManager em;
          @Override
          public void deleteWithReference(Long id) {
          //因為Group中沒有與User的關聯,只能用笨辦法,查詢出擁有該權限組的用戶, 并刪除該用戶的權限組.
          Group group = em.find(Group.class, id);
          List<User> users = em.createQuery(QUERY_USER_BY_GROUPID).setParameter(1, id).getResultList();
          for (User u : users) {
          u.getGroupList().remove(group);
          }
          em.remove(group);
          }
          }

          posted @ 2012-09-13 20:25 云自無心水自閑 閱讀(505) | 評論 (0)編輯 收藏

          造成這個錯誤的原因主要是一些系統文件夾system權限丟失。
          所以只要把權限加回去就行了。

          我主要查看了
          c:\windows\installer
          C:\Documents and Settings\<user name>\Local Settings\Temp
          右鍵點擊目錄,點安全選項頁,在“組和用戶名稱”列表中把system用戶添加進去,并在下面的權限列表中勾選“完全控制” 即可

          posted @ 2012-09-06 20:18 云自無心水自閑 閱讀(1765) | 評論 (0)編輯 收藏

          Spring Security中指定session超時后跳轉的頁面

          在xml配置文件中加入:<session-management invalid-session-url="/session-timeout.htm" />

          posted @ 2011-08-31 07:25 云自無心水自閑 閱讀(3205) | 評論 (0)編輯 收藏


          在applicationContext.xml中定義了一個DataSource:<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" />
          但是在代碼中,使用anotation進行注入的時候,卻總是找不到這個dataSource.

              @Autowired
              public void setDataSource(DataSource dataSource) {
                  jdbcTemplate = new JdbcTemplate(dataSource);
                  jdbcInsert = new SimpleJdbcInsert(dataSource);
              }

          最后終于想明白了,原因大概是這樣的,使用autowired的時候,默認是根據類型來匹配的,在xml中定義的類型是:BasicDataSource,而不是接口DataSource,所以默認情況下這樣是無法自動裝配的。解決辦法是指令使用名字來進行bean的匹配,也就是用Qualifier指定bean的id.

              @Autowired
              public void setDataSource(@Qualifier("dataSource") DataSource dataSource) {
                  jdbcTemplate = new JdbcTemplate(dataSource);
                  jdbcInsert = new SimpleJdbcInsert(dataSource);
              }


          另外一點,在網上搜索的過程中發現有不少人都有類似的問題,但是他們的原因是沒有正確使用spring的注入,而是自己在代碼中new了一個Dao的實例,這樣的話,spring是無法將dataSource注入到dao的實例中的

          posted @ 2011-08-26 08:57 云自無心水自閑 閱讀(3854) | 評論 (0)編輯 收藏

          僅列出標題
          共29頁: First 上一頁 3 4 5 6 7 8 9 10 11 下一頁 Last 
          主站蜘蛛池模板: 长寿区| 玉田县| 渭南市| 远安县| 钟祥市| 瑞安市| 长垣县| 宜春市| 胶州市| 阳春市| 丽江市| 城市| 南召县| 龙门县| 苍山县| 滨州市| 寿宁县| 阜阳市| 岢岚县| 沽源县| 阿克陶县| 喀喇| 山阳县| 嘉善县| 云林县| 永德县| 亳州市| 当雄县| 赣州市| 镇安县| 五常市| 长宁县| 宜兰市| 兰考县| 德令哈市| 虎林市| 洪泽县| 长垣县| 宜春市| 常宁市| 甘孜县|