java數據庫鏈接池實現原理

1、爲何在鏈接數據庫時要使用鏈接池

 數據庫鏈接是一種關鍵的有限的昂貴的資源,這一點在多用戶的網頁應用程序中體現得尤其突出。  一個數據庫鏈接對象均對應一個物理數據庫鏈接,每次操做都打開一個物理鏈接,使用完都關閉鏈接,這樣形成系統的 性能低下。 數據庫鏈接池的解決方案是在應用程序啓動時創建足夠的數據庫鏈接,並講這些鏈接組成一個鏈接池(簡單說:在一個「池」裏放了好多半成品的數據庫聯接對象),由應用程序動態地對池中的鏈接進行申請、使用和釋放。對於多於鏈接池中鏈接數的併發請求,應該在請求隊列中排隊等待。而且應用程序能夠根據池中鏈接的使用率,動態增長或減小池中的鏈接數。 鏈接池技術儘量多地重用了消耗內存地資源,大大節省了內存,提升了服務器地服務效率,可以支持更多的客戶服務。經過使用鏈接池,將大大提升程序運行效率,同時,咱們能夠經過其自身的管理機制來監視數據庫鏈接的數量、使用狀況等。 java

2、數據庫鏈接池的基本原理

數據庫鏈接池的基本思想就是爲數據庫鏈接 創建一個「緩衝池」。預先在緩衝池中放入必定數量的鏈接,當須要創建數據庫鏈接時,只需從「緩衝池」中取出一個,使用完畢以後再放回去。咱們能夠經過設定 鏈接池最大鏈接數來防止系統無盡的與數據庫鏈接。更爲重要的是咱們能夠經過鏈接池的管理機制監視數據庫的鏈接的數量?使用狀況,爲系統開發?測試及性能調 整提供依據。sql

 

3、數據庫鏈接池的工做原理

鏈接池的工做原理主要由三部分組成,分別爲鏈接池的創建、鏈接池中鏈接的使用管理、鏈接池的關閉。數據庫

        第1、鏈接池的創建。通常在系統初始化時,鏈接池會根據系統配置創建,並在池中建立了幾個鏈接對象,以便使用時能從鏈接池中獲取。鏈接池中的鏈接不能隨意建立和關閉,這樣避免了鏈接隨意創建和關閉形成的系統開銷。Java中提供了不少容器類能夠方便的構建鏈接池,例如Vector、Stack等。服務器

        第2、鏈接池的管理。鏈接池管理策略是鏈接池機制的核心,鏈接池內鏈接的分配和釋放對系統的性能有很大的影響。其管理策略是:多線程

        當客戶請求數據庫鏈接時,首先查看鏈接池中是否有空閒鏈接,若是存在空閒鏈接,則將鏈接分配給客戶使用;若是沒有空閒鏈接,則查看當前所開的鏈接數是否已經達到最大鏈接數,若是沒達到就從新建立一個鏈接給請求的客戶;若是達到就按設定的最大等待時間進行等待,若是超出最大等待時間,則拋出異常給客戶。併發

        當客戶釋放數據庫鏈接時,先判斷該鏈接的引用次數是否超過了規定值,若是超過就從鏈接池中刪除該鏈接,不然保留爲其餘客戶服務。app

        該策略保證了數據庫鏈接的有效複用,避免頻繁的創建、釋放鏈接所帶來的系統資源開銷。函數

        第3、鏈接池的關閉。當應用程序退出時,關閉鏈接池中全部的鏈接,釋放鏈接池相關的資源,該過程正好與建立相反。sqlserver

 

4、鏈接池關鍵問題分析

  一、併發問題性能

  爲了使鏈接管理服務具備最大的通用性,必須考慮多線程環境,即併發問題。這個問題相對比較好解決,由於Java語言自身提供了對併發管理的支 持,使用synchronized關鍵字便可確保線程是同步的。使用方法爲直接在類方法前面加上synchronized關鍵字,如:

  public synchronized Connection getConnection()

  二、多數據庫服務器和多用戶

  對於大型的企業級應用,經常須要同時鏈接不一樣的數據庫(如鏈接Oracle和Sybase)。如何鏈接不一樣的數據庫呢?咱們採用的策略是:設計 一個符合單例模式的鏈接池管理類,在鏈接池管理類的惟一實例被建立時讀取一個資源文件,其中資源文件中存放着多個數據庫的url地址()?用戶名()?密 碼()等信息。如 tx.url=172.21.15.123:5000/tx_it,tx.user=yang,tx.password=yang321。根據資源文件提 供的信息,建立多個鏈接池類的實例,每個實例都是一個特定數據庫的鏈接池。鏈接池管理類實例爲每一個鏈接池實例取一個名字,經過不一樣的名字來管理不一樣的連 接池。

  對於同一個數據庫有多個用戶使用不一樣的名稱和密碼訪問的狀況,也能夠經過資源文件處理,即在資源文件中設置多個具備相同url地址,但具備不一樣用戶名和密碼的數據庫鏈接信息。

  三、事務處理

  咱們知道,事務具備原子性,此時要求對數據庫的操做符合「ALL-ALL-NOTHING」原則,即對於一組SQL語句要麼全作,要麼全不作。

  在Java語言中,Connection類自己提供了對事務的支持,能夠經過設置Connection的AutoCommit屬性爲 false,而後顯式的調用commit或rollback方法來實現。但要高效的進行Connection複用,就必須提供相應的事務支持機制。可採用 每個事務獨佔一個鏈接來實現,這種方法能夠大大下降事務管理的複雜性。

  四、鏈接池的分配與釋放

  鏈接池的分配與釋放,對系統的性能有很大的影響。合理的分配與釋放,能夠提升鏈接的複用度,從而下降創建新鏈接的開銷,同時還能夠加快用戶的訪問速度。

  對於鏈接的管理可以使用空閒池。即把已經建立但還沒有分配出去的鏈接按建立時間存放到一個空閒池中。每當用戶請求一個鏈接時,系統首先檢查空閒池內 有沒有空閒鏈接。若是有就把創建時間最長(經過容器的順序存放實現)的那個鏈接分配給他(實際是先作鏈接是否有效的判斷,若是可用就分配給用戶,如不可用 就把這個鏈接從空閒池刪掉,從新檢測空閒池是否還有鏈接);若是沒有則檢查當前所開鏈接池是否達到鏈接池所容許的最大鏈接數(maxConn),若是沒有 達到,就新建一個鏈接,若是已經達到,就等待必定的時間(timeout)。若是在等待的時間內有鏈接被釋放出來就能夠把這個鏈接分配給等待的用戶,若是 等待時間超過預約時間timeout,則返回空值(null)。系統對已經分配出去正在使用的鏈接只作計數,當使用完後再返還給空閒池。對於空閒鏈接的狀 態,可開闢專門的線程定時檢測,這樣會花費必定的系統開銷,但能夠保證較快的響應速度。也可採起不開闢專門線程,只是在分配前檢測的方法。

  五、鏈接池的配置與維護

  鏈接池中到底應該放置多少鏈接,才能使系統的性能最佳?系統可採起設置最小鏈接數(minConn)和最大鏈接數(maxConn)來控制鏈接 池中的鏈接。最小鏈接數是系統啓動時鏈接池所建立的鏈接數。若是建立過多,則系統啓動就慢,但建立後系統的響應速度會很快;若是建立過少,則系統啓動的很 快,響應起來卻慢。這樣,能夠在開發時,設置較小的最小鏈接數,開發起來會快,而在系統實際使用時設置較大的,由於這樣對訪問客戶來講速度會快些。最大連 接數是鏈接池中容許鏈接的最大數目,具體設置多少,要看系統的訪問量,可經過反覆測試,找到最佳點。

  如何確保鏈接池中的最小鏈接數呢?有動態和靜態兩種策略。動態即每隔必定時間就對鏈接池進行檢測,若是發現鏈接數量小於最小鏈接數,則補充相應數量的新鏈接,以保證鏈接池的正常運轉。靜態是發現空閒鏈接不夠時再去檢查。

 

5、鏈接池實現代碼(java)

[java] view plain copy

  1. package book.util;  
  2. import java.sql.Connection;  
  3. import java.sql.DatabaseMetaData;  
  4. import java.sql.Date;  
  5. import java.sql.Driver;  
  6. import java.sql.DriverManager;  
  7. import java.sql.PreparedStatement;  
  8. import java.sql.ResultSet;  
  9. import java.sql.SQLException;  
  10. import java.sql.Statement;  
  11. import java.util.Vector;  
  12. public class Pool {  
  13.     public static void main(String[] args) {  
  14.         Pool pool = new Pool("com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://localhost:1433;DataBaseName=Book","sa","aaaaaa");  
  15.         try {  
  16.             pool.createConnections(4);  
  17.               
  18.         } catch (SQLException e) {  
  19.             e.printStackTrace();  
  20.         }  
  21.         Connection conn = pool.getConnection();   
  22.         try {  
  23.             String sql = "select * from allbook";  
  24.             PreparedStatement ps;  
  25.             ps = conn.prepareStatement(sql);  
  26.             ResultSet rs=ps.executeQuery();  
  27.             while(rs.next()){  
  28.                 System.out.println(rs.getString("BOOKNAME"));  
  29.             }  
  30.         } catch (SQLException e) {  
  31.             // TODO Auto-generated catch block  
  32.             e.printStackTrace();  
  33.         }finally{  
  34.             pool.returnConnection(conn);  
  35.         }  
  36.         //long startTime=System.currentTimeMillis();   
  37.         //long endTime=System.currentTimeMillis();   
  38.         //System.out.println("程序運行時間: "+(endTime-startTime)+"ms");   
  39.     }  
  40.       
  41.     private String jdbcDriver = "";//數據庫驅動  
  42.     private String dbUrl = "";//數據庫url  
  43.     private String dbUsername = "";//數據庫用戶名  
  44.     private String dbPassword = "";//數據庫密碼  
  45.     private String testTable = "";  
  46.     private int initialConnectionsNum = 10;//鏈接池初始鏈接數  
  47.     private int maxConnectionsNum = 50;//鏈接池最大鏈接數  
  48.     private int incrementalConnections = 5;//每次動態添加的鏈接數  
  49.     private Vector<PooledConnection> connections = null;//向量,存放鏈接池中的鏈接,初始爲空  
  50.       
  51.     /*無參構造函數*/  
  52.     public Pool()  
  53.     {}  
  54.       
  55.     /*帶參數的構造函數 
  56.      * 初始化數據庫驅動、數據庫url、數據庫用戶名、數據庫密碼、測試表 
  57.      * */  
  58.     public Pool(String driver, String url, String name, String pass)  
  59.     {  
  60.         this.jdbcDriver = driver;  
  61.         this.dbUrl = url;  
  62.         this.dbUsername = name;  
  63.         this.dbPassword = pass;  
  64.         //this.testTable = table;  
  65.         try {  
  66.             this.createPool();  
  67.         } catch (InstantiationException e) {  
  68.             // TODO Auto-generated catch block  
  69.             e.printStackTrace();  
  70.         } catch (IllegalAccessException e) {  
  71.             // TODO Auto-generated catch block  
  72.             e.printStackTrace();  
  73.         } catch (ClassNotFoundException e) {  
  74.             // TODO Auto-generated catch block  
  75.             e.printStackTrace();  
  76.         } catch (SQLException e) {  
  77.             // TODO Auto-generated catch block  
  78.             e.printStackTrace();  
  79.         }  
  80.     }  
  81.       
  82.     /*函數,建立鏈接池*/  
  83.     public synchronized void createPool()   
  84.     throws InstantiationException, IllegalAccessException,   
  85.     ClassNotFoundException, SQLException  
  86.     {  
  87.         /*確保鏈接池爲建立,若是已經建立,則保存鏈接的向量不爲空 
  88.          * */  
  89.         if (this.connections != null)  
  90.         {  
  91.             return ;  
  92.         }  
  93.         //驅動器實例化  
  94.         Driver driver = (Driver)(Class.forName(this.jdbcDriver).newInstance());  
  95.         //註冊驅動器  
  96.         DriverManager.registerDriver(driver);  
  97.         //建立保存鏈接的向量  
  98.         this.connections = new Vector<PooledConnection>();  
  99.         //建立數據庫鏈接  
  100.         this.createConnections(this.initialConnectionsNum);  
  101.     }  
  102.       
  103.     /*函數,建立數據庫鏈接 
  104.      * */  
  105.     private void createConnections (int num) throws SQLException  
  106.     {  
  107.         /*循環建立鏈接 
  108.          * 須要首先檢查當前鏈接數是否已經超出鏈接池最大鏈接數 
  109.          * */  
  110.         for (int i = 0; i < num; ++i)  
  111.         {  
  112.             //檢查  
  113.             if (this.connections.size() >= this.maxConnectionsNum)  
  114.             {  
  115.                 return;  
  116.             }  
  117.             //建立鏈接  
  118.             this.connections.addElement  
  119.             (new PooledConnection(newConnection()));  
  120.         }  
  121.           
  122.     }  
  123.       
  124.     /*函數,建立一個數據庫鏈接*/  
  125.     private Connection newConnection() throws SQLException  
  126.     {  
  127.         /*建立鏈接*/  
  128.         Connection con = DriverManager.getConnection(this.dbUrl,   
  129.                 this.dbUsername, this.dbPassword);  
  130.         /*若是是第一次建立鏈接,則檢查所鏈接的數據庫的容許最大鏈接數是否小於 
  131.          * 咱們所設定的最大鏈接數*/  
  132.         if (this.connections.size() == 0)  
  133.         {  
  134.             DatabaseMetaData metadata = con.getMetaData();  
  135.             //獲得數據庫最大鏈接數  
  136.             int dbMaxConnectionsNum = metadata.getMaxConnections();  
  137.             //若是數據庫最大鏈接數更小,則更改咱們所設定的鏈接池最大鏈接數  
  138.             if (dbMaxConnectionsNum > 0   
  139.                     && this.maxConnectionsNum > dbMaxConnectionsNum)  
  140.             {  
  141.                 this.maxConnectionsNum = dbMaxConnectionsNum;  
  142.             }  
  143.         }  
  144.         return con;  
  145.     }  
  146.       
  147.     /*函數,獲得一個可用鏈接 
  148.      * */  
  149.     public synchronized Connection getConnection ()   
  150.     {  
  151.         Connection con = null;  
  152.         /*檢查鏈接池是否已經創建*/  
  153.         if (this.connections == null)  
  154.         {  
  155.             return con;  
  156.         }  
  157.         //獲得一個可用鏈接  
  158.         try {  
  159.             con = this.getFreeConnection();  
  160.         } catch (SQLException e) {  
  161.             // TODO Auto-generated catch block  
  162.             e.printStackTrace();  
  163.         }  
  164.         //若是未找到合適鏈接,循環等待、查找,知道找到合適鏈接  
  165.         while(con == null)  
  166.         {  
  167.             this.wait(30);  
  168.             try {  
  169.                 con = this.getFreeConnection();  
  170.             } catch (SQLException e) {  
  171.                 // TODO Auto-generated catch block  
  172.                 e.printStackTrace();  
  173.             }  
  174.         }  
  175.           
  176.         return con;  
  177.     }  
  178.       
  179.       
  180.     /*函數,獲得一個可用鏈接*/  
  181.     private Connection getFreeConnection() throws SQLException  
  182.     {  
  183.         Connection con = null;  
  184.         //查找一個可用鏈接  
  185.         con = this.findFreeConnection();  
  186.         //若是未找到可用鏈接,就創建一些新的鏈接,再次查找  
  187.         if (con == null)  
  188.         {  
  189.             this.createConnections(this.incrementalConnections);  
  190.             //再次查找  
  191.             con = this.findFreeConnection();  
  192.         }  
  193.         return con;  
  194.     }  
  195.       
  196.       
  197.     /*函數,從現有鏈接中查找一個可用鏈接 
  198.      * 在現有的鏈接中(向量connections中)找到一個空閒鏈接, 
  199.      * 並測試這個連接是否可用,若不可用則從新創建鏈接,替換原來的鏈接*/  
  200.     private Connection findFreeConnection () throws SQLException  
  201.     {  
  202.         Connection con = null;  
  203.         for (int i = 0; i < this.connections.size(); ++i)  
  204.         {  
  205.             PooledConnection pol = (PooledConnection)this.connections.get(i);  
  206.             if (!pol.isBusy())  
  207.             {  
  208.                 /*若是此連接未被使用,則返回這個鏈接並,設置正在使用標誌*/  
  209.                 con = pol.getCon();  
  210.                 pol.setBusy(true);  
  211.                 /*測試鏈接是否可用*/  
  212.                 if (!this.testCon(con))  
  213.                 {  
  214.                     con = this.newConnection();  
  215.                     pol.setCon(con);  
  216.                 }  
  217.                 break;  
  218.             }  
  219.         }  
  220.         return con;  
  221.     }  
  222.       
  223.     /*函數,測試鏈接是否可用 
  224.      * */  
  225.     private boolean testCon (Connection con)  
  226.     {  
  227.         boolean useable = true;  
  228.         try  
  229.         {  
  230.             Statement st = con.createStatement();  
  231.             ResultSet rs = st.executeQuery("select count(*) from " + this.testTable);  
  232.             rs.next();  
  233.         }  
  234.         catch(SQLException e)  
  235.         {  
  236.             /*上面拋出異常,鏈接不可用,關閉*/  
  237.             useable = false;  
  238.             this.closeConnection(con);  
  239.         }  
  240.         return useable;  
  241.     }  
  242.       
  243.     /*函數,將使用完畢的鏈接放回鏈接池中 
  244.      * */  
  245.     public void returnConnection(Connection con)  
  246.     {  
  247.         /*確保鏈接池存在*/  
  248.         if (this.connections == null)  
  249.         {  
  250.             return ;  
  251.         }  
  252.         for (int i = 0; i < this.connections.size(); ++i)  
  253.         {  
  254.             PooledConnection pool = this.connections.get(i);  
  255.             //找到相應鏈接,設置正在使用標誌爲false  
  256.             if (con == pool.getCon())  
  257.             {  
  258.                 pool.setBusy(false);  
  259.             }  
  260.         }  
  261.           
  262.     }  
  263.       
  264.     /*函數,刷新鏈接池中的鏈接*/  
  265.     public synchronized void refreshConneciontPool () throws SQLException  
  266.     {  
  267.         /*確保鏈接池存在*/  
  268.         if (this.connections == null)  
  269.         {  
  270.             return ;  
  271.         }  
  272.         for (int i = 0; i < this.connections.size(); ++i)  
  273.         {  
  274.             PooledConnection pool = this.connections.get(i);  
  275.             if (pool.isBusy())  
  276.             {  
  277.                 this.wait(5000);  
  278.             }  
  279.             this.closeConnection(pool.getCon());  
  280.             pool.setCon(this.newConnection());  
  281.             pool.setBusy(false);  
  282.         }  
  283.     }  
  284.   
  285.     /*函數,關閉鏈接池*/  
  286.     public void closeConnectionPool()  
  287.     {  
  288.         /*確保鏈接池存在*/  
  289.         if (this.connections == null)  
  290.         {  
  291.             return ;  
  292.         }  
  293.         for (int i = 0; i < this.connections.size(); ++i)  
  294.         {  
  295.             PooledConnection pool = this.connections.get(i);  
  296.             if (pool.isBusy())  
  297.             {  
  298.                 this.wait(5000);  
  299.             }  
  300.             this.closeConnection(pool.getCon());  
  301.             this.connections.remove(i);  
  302.         }  
  303.         this.connections = null;  
  304.     }  
  305.       
  306.     /*函數,暫時無可用鏈接,進入等待隊列等待m秒,再試 
  307.      * */  
  308.     private void wait(int mSecond)  
  309.     {  
  310.         try {  
  311.             Thread.sleep(mSecond);  
  312.         } catch (InterruptedException e) {  
  313.             // TODO Auto-generated catch block  
  314.             e.printStackTrace();  
  315.         }  
  316.     }  
  317.       
  318.     /** 
  319.      * @return the jdbcDriver 
  320.      */  
  321.     public String getJdbcDriver() {  
  322.         return jdbcDriver;  
  323.     }  
  324.   
  325.     /** 
  326.      * @param jdbcDriver the jdbcDriver to set 
  327.      */  
  328.     public void setJdbcDriver(String jdbcDriver) {  
  329.         this.jdbcDriver = jdbcDriver;  
  330.     }  
  331.   
  332.     /** 
  333.      * @return the dbUrl 
  334.      */  
  335.     public String getDbUrl() {  
  336.         return dbUrl;  
  337.     }  
  338.   
  339.     /** 
  340.      * @param dbUrl the dbUrl to set 
  341.      */  
  342.     public void setDbUrl(String dbUrl) {  
  343.         this.dbUrl = dbUrl;  
  344.     }  
  345.   
  346.     /** 
  347.      * @return the dbUsername 
  348.      */  
  349.     public String getDbUsername() {  
  350.         return dbUsername;  
  351.     }  
  352.   
  353.     /** 
  354.      * @param dbUsername the dbUsername to set 
  355.      */  
  356.     public void setDbUsername(String dbUsername) {  
  357.         this.dbUsername = dbUsername;  
  358.     }  
  359.   
  360.     /** 
  361.      * @return the dbPassword 
  362.      */  
  363.     public String getDbPassword() {  
  364.         return dbPassword;  
  365.     }  
  366.   
  367.     /** 
  368.      * @param dbPassword the dbPassword to set 
  369.      */  
  370.     public void setDbPassword(String dbPassword) {  
  371.         this.dbPassword = dbPassword;  
  372.     }  
  373.   
  374.     /** 
  375.      * @return the testTable 
  376.      */  
  377.     public String getTestTable() {  
  378.         return testTable;  
  379.     }  
  380.   
  381.     /** 
  382.      * @param testTable the testTable to set 
  383.      */  
  384.     public void setTestTable(String testTable) {  
  385.         this.testTable = testTable;  
  386.     }  
  387.   
  388.     /** 
  389.      * @return the initialConnectionsNum 
  390.      */  
  391.     public int getInitialConnectionsNum() {  
  392.         return initialConnectionsNum;  
  393.     }  
  394.   
  395.     /** 
  396.      * @param initialConnectionsNum the initialConnectionsNum to set 
  397.      */  
  398.     public void setInitialConnectionsNum(int initialConnectionsNum) {  
  399.         this.initialConnectionsNum = initialConnectionsNum;  
  400.     }  
  401.   
  402.     /** 
  403.      * @return the maxConnectionsNum 
  404.      */  
  405.     public int getMaxConnectionsNum() {  
  406.         return maxConnectionsNum;  
  407.     }  
  408.   
  409.     /** 
  410.      * @param maxConnectionsNum the maxConnectionsNum to set 
  411.      */  
  412.     public void setMaxConnectionsNum(int maxConnectionsNum) {  
  413.         this.maxConnectionsNum = maxConnectionsNum;  
  414.     }  
  415.   
  416.     /** 
  417.      * @return the incrementalConnections 
  418.      */  
  419.     public int getIncrementalConnections() {  
  420.         return incrementalConnections;  
  421.     }  
  422.   
  423.     /** 
  424.      * @param incrementalConnections the incrementalConnections to set 
  425.      */  
  426.     public void setIncrementalConnections(int incrementalConnections) {  
  427.         this.incrementalConnections = incrementalConnections;  
  428.     }  
  429.   
  430.     /** 
  431.      * @return the connections 
  432.      */  
  433.     public Vector<PooledConnection> getConnections() {  
  434.         return connections;  
  435.     }  
  436.   
  437.     /** 
  438.      * @param connections the connections to set 
  439.      */  
  440.     public void setConnections(Vector<PooledConnection> connections) {  
  441.         this.connections = connections;  
  442.     }  
  443.   
  444.     /*函數,鏈接使用完畢,關閉鏈接*/  
  445.     private void closeConnection (Connection con)  
  446.     {  
  447.         try  
  448.         {  
  449.             con.close();  
  450.         }  
  451.         catch(SQLException e)  
  452.         {  
  453.             e.printStackTrace();  
  454.         }  
  455.     }  
  456.       
  457.       
  458.     /*內部使用的保存數據庫鏈接的類 
  459.      * 兩個成員變量:鏈接、是否正在使用*/  
  460.     class PooledConnection  
  461.     {  
  462.         private Connection con = null;//鏈接  
  463.         private boolean busy = false;//是否正在使用,默認爲非  
  464.           
  465.         /*構造函數*/  
  466.         public PooledConnection(Connection con)  
  467.         {  
  468.             this.con = con;  
  469.         }  
  470.   
  471.         /** 
  472.          * @return the con 
  473.          */  
  474.         public Connection getCon() {  
  475.             return con;  
  476.         }  
  477.   
  478.         /** 
  479.          * @param con the con to set 
  480.          */  
  481.         public void setCon(Connection con) {  
  482.             this.con = con;  
  483.         }  
  484.   
  485.         /** 
  486.          * @return the busy 
  487.          */  
  488.         public boolean isBusy() {  
  489.             return busy;  
  490.         }  
  491.   
  492.         /** 
  493.          * @param busy the busy to set 
  494.          */  
  495.         public void setBusy(boolean busy) {  
  496.             this.busy = busy;  
  497.         }  
  498.     }  
  499.   
  500. }  
相關文章
相關標籤/搜索