daixj110

          2010年10月20日

          學(xué)習(xí)知識(shí)轉(zhuǎn)載

          用RMI實(shí)現(xiàn)基于Java的分布式計(jì)算
          http://developer.51cto.com/art/200906/130417.htm
          java內(nèi)存分配
          http://developer.51cto.com/art/201009/225071.htm
          內(nèi)存溢出解決辦法
          http://developer.51cto.com/art/200906/129346.htm

          java引用
          http://developer.51cto.com/art/200906/130447.htm
          linux上java環(huán)境搭建
          http://developer.51cto.com/art/200511/10736.htm

          設(shè)計(jì)模式
          http://lavasoft.blog.51cto.com/62575/d-11
          Java內(nèi)存模型中的三個(gè)代
          http://developer.51cto.com/art/200909/153154.htm

          Java垃圾回收機(jī)制淺析
          http://developer.51cto.com/art/200906/130855.htm

          20個(gè)開發(fā)人員非常有用的Java功能代碼
          http://developer.51cto.com/art/200905/124291.htm

          posted @ 2010-10-30 19:37 游龍! 閱讀(160) | 評(píng)論 (0)編輯 收藏

          詳解Listener監(jiān)聽Http Session

          Listener 是Servlet 的監(jiān)聽器,它可以監(jiān)聽客戶端的請(qǐng)求、服務(wù)端的操作等。通過監(jiān)聽器,可以自動(dòng)激發(fā)一些操作,比如監(jiān)聽在線的用戶的數(shù)量。當(dāng)增加一個(gè) Http Session時(shí),就激發(fā)session Created(Http Session Event se)方法,這樣就可以給在線人數(shù)加1。常用的監(jiān)聽接口有以下幾個(gè):

          Servlet Context Attribute Listener監(jiān)聽對(duì)Servlet Context 屬性的操作,比如增加、刪除、修改屬性。

          Servlet Context Listener監(jiān)聽Servlet Context 。當(dāng)創(chuàng)建Servlet Context 時(shí),激發(fā)Context Initialized (Servlet Context Event sce)方法;當(dāng)銷毀Servlet Context 時(shí),激發(fā)Context Destroyed(Servlet Context Event sce)方法。

          Http Session Listener監(jiān)聽Http Session的操作。當(dāng)創(chuàng)建一個(gè)Session時(shí),激發(fā)session Created(Http Session Event se)方法;當(dāng)銷毀一個(gè)Session時(shí),激發(fā)session Destroyed (Http Session Event se)方法。

          Http Session Attribute Listener監(jiān)聽Http Session中的屬性的操作。當(dāng)在Session增加一個(gè)屬性時(shí),激發(fā)attribute Added (Http Session Binding Event se) 方法;當(dāng)在Session刪除一個(gè)屬性時(shí),激發(fā)attribute Removed(Http Session Binding Event se)方法;當(dāng)在Session屬性被重新設(shè)置時(shí),激發(fā)attribute Replaced(Http Session Binding Event se) 方法。

          下面我們開發(fā)一個(gè)具體的例子,這個(gè)監(jiān)聽器能夠統(tǒng)計(jì)在線的人數(shù)。在Servlet Context 初始化和銷毀時(shí),在服務(wù)器控制臺(tái)打印對(duì)應(yīng)的信息。當(dāng)Servlet Context 里的屬性增加、改變、刪除時(shí),在服務(wù)器控制臺(tái)打印對(duì)應(yīng)的信息。

          要獲得以上的功能,監(jiān)聽器必須實(shí)現(xiàn)以下3個(gè)接口:
          ◆HttpSessionListener
          ◆Servlet Context Listener
          ◆Servlet Context AttributeListener

          import javax.servlet.http.*;  
          import javax.servlet.*
           
          public class OnLineCountListener implements HttpSessionListener,  ServletContextListener,ServletContextAttributeListener  {  
          private int count;  
          private ServletContext context = null;  
          public OnLineCountListener()  {  count=0;  //setContext();  
          }
            //創(chuàng)建一個(gè)session時(shí)激發(fā)  
          public void sessionCreated(HttpSessionEvent se)  {  
          count
          ++;  setContext(se);  
          }
            //當(dāng)一個(gè)session失效時(shí)激發(fā)  
          public void sessionDestroyed(HttpSessionEvent se)  {  
          count
          --;  
          setContext(se);  
          }
            //設(shè)置context的屬性,它將激發(fā)attributeReplaced或attributeAdded方法  
          public void setContext(HttpSessionEvent se)  {  
          se.getSession().getServletContext().  setAttribute(
          "onLine",new Integer(count)); 
           }
            //增加一個(gè)新的屬性時(shí)激發(fā)  
          public void attributeAdded(ServletContextAttributeEvent event) 
           log(
          "attributeAdded('" + event.getName() + "', '" +  event.getValue() + "')"); 
           }
            //刪除一個(gè)新的屬性時(shí)激發(fā)  public void attributeRemoved(ServletContextAttributeEvent event) {  
          log("attributeRemoved('" + event.getName() + "', '" +  event.getValue() + "')");  }
            //屬性被替代時(shí)激發(fā)  
          public void attributeReplaced(ServletContextAttributeEvent event) {  
          log(
          "attributeReplaced('" + event.getName() + "', '" +  event.getValue() + "')");  
          }
            //context刪除時(shí)激發(fā) 
           public void contextDestroyed(ServletContextEvent event) {  
          log(
          "contextDestroyed()");  this.context = null;  }
            //context初始化時(shí)激發(fā)  
          public void contextInitialized(ServletContextEvent event) {  
          this.context = event.getServletContext();  log("contextInitialized()");  
          }
            
          private void log(String message) {  System.out.println("ContextListener: " + message);  
          }
            

          在OnLine Count Listener 里,用count代表當(dāng)前在線的人數(shù),OnLine Count Listener將在Web服務(wù)器啟動(dòng)時(shí)自動(dòng)執(zhí)行。當(dāng) OnLine Count Listener構(gòu)造好后,把count設(shè)置為0。每增加一個(gè)Session,OnLine Count Listener會(huì)自動(dòng)調(diào)用 session Created(Http Session Event se)方法;每銷毀一個(gè)Session,OnLine Count Listener會(huì)自動(dòng)調(diào)用session Destroyed (Http Session Event se)方法。當(dāng)調(diào)用session Created(Http Session Event se)方法時(shí),說(shuō)明又有一個(gè)客戶在請(qǐng)求,此時(shí)使在線的人數(shù)(count)加1,并且把count寫到Servlet Context 中。 Servlet Context 的信息是所有客戶端共享的,這樣,每個(gè)客戶端都可以讀取到當(dāng)前在線的人數(shù)。

          從作用域范圍來(lái)說(shuō),Servlet 的作用域有Servlet Context ,Http Session,Servlet Request.以上是Listener監(jiān)聽Http Session

          轉(zhuǎn)自:http://developer.51cto.com/art/200907/134756.htm

          posted @ 2010-10-30 18:12 游龍! 閱讀(284) | 評(píng)論 (0)編輯 收藏

          臟數(shù)據(jù)

          丟失修改:當(dāng)一個(gè)事務(wù)修改了數(shù)據(jù),并且這種修改還沒有還沒有提交到數(shù)據(jù)庫(kù)中時(shí),另外一個(gè)事務(wù)又對(duì)同樣的數(shù)據(jù)進(jìn)行了修改,并且把這種修改提交到了數(shù)據(jù)庫(kù)中。這樣,數(shù)據(jù)庫(kù)中沒有出現(xiàn)第一個(gè)事務(wù)修改數(shù)據(jù)的結(jié)果,好像這種數(shù)據(jù)修改丟失了一樣。
            臟讀:當(dāng)一個(gè)事務(wù)正在訪問數(shù)據(jù),并對(duì)數(shù)據(jù)進(jìn)行了修改,而這種修改還沒有提交到數(shù)據(jù)庫(kù)中,這時(shí),另一個(gè)事務(wù)也訪問這個(gè)數(shù)據(jù),然后使用了這個(gè)數(shù)據(jù)。因?yàn)檫@個(gè)數(shù)據(jù)是還沒有提交的數(shù)據(jù),那么另一個(gè)事務(wù)讀到的這個(gè)數(shù)據(jù)是臟數(shù)據(jù),依據(jù)臟數(shù)據(jù)所做的操作可能是不正確的。
            不可重復(fù)讀:在一個(gè)事務(wù)內(nèi),多次讀同一數(shù)據(jù)。在這個(gè)事務(wù)還沒有結(jié)束時(shí),另一個(gè)事務(wù)也訪問該同一數(shù)據(jù),那么,在第一個(gè)事務(wù)中的兩次讀數(shù)據(jù)之間,由于第二個(gè)事務(wù)的修改,第一個(gè)事務(wù)兩次讀到的數(shù)據(jù)可能是不一樣的。


          hibernate中的臟數(shù)據(jù)
          http://developer.51cto.com/art/200906/129861.htm

          posted @ 2010-10-29 23:01 游龍! 閱讀(268) | 評(píng)論 (0)編輯 收藏

          一些很好的技術(shù)博客、網(wǎng)站

          http://www.aygfsteel.com/shiliqiang/

          java網(wǎng)站
          http://wiki.huihoo.com/wiki/Java

          linux學(xué)習(xí)博客
          http://blog.csdn.net/eroswang/archive/2008/10/02/3008146.aspx


          更新中

          posted @ 2010-10-20 22:12 游龍! 閱讀(176) | 評(píng)論 (0)編輯 收藏

          <2010年10月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 灵宝市| 海丰县| 沙雅县| 遂溪县| 祁东县| 红桥区| 西安市| 罗田县| 陈巴尔虎旗| 华池县| 温州市| 申扎县| 深州市| 方城县| 大新县| 吉木萨尔县| 东丰县| 汝城县| 贵定县| 板桥市| 嘉峪关市| 同心县| 秀山| 广汉市| 旌德县| 浮山县| 岚皋县| 翁源县| 通化市| 永宁县| 韶关市| 太谷县| 邻水| 闽侯县| 尼玛县| 农安县| 乐安县| 类乌齐县| 溧阳市| 华蓥市| 沾益县|