<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    七段

    無論怎樣,請讓我先感謝一下國家。

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      35 Posts :: 2 Stories :: 7 Comments :: 0 Trackbacks

    2010年4月13日 #

    有25匹馬,每匹馬都以一個固定不變的速度奔跑,每匹馬的速度都不一樣,如果讓你找出跑的最快的5匹馬,最少需要組織多少場比賽?注:每場比賽最多只能5匹馬參賽。
    re:悲觀10場,樂觀7場。
    posted @ 2012-03-07 21:17 sevenduan 閱讀(833) | 評論 (1)編輯 收藏

    Eclipse:
    ctrl+o
    ctrl+space
    ctrl+t
    ctrl+k
    ctrl+f8/f9/f10

    alt+shift+x , t/j
    alt+shift+d , t/j

    Command:
    cd -
    tab
    ctrl+a/e
    ctrl+u/k/w

    Vim
    shift+g
    m+'mark'
    `+'mark'
    . (repeat)



    posted @ 2010-08-07 23:14 sevenduan 閱讀(247) | 評論 (0)編輯 收藏

    Framework Supported log levels Standard appenders Popularity Cost / licence
    Log4J FATAL ERROR WARN INFO DEBUG TRACE AsyncAppender, JDBCAppender, JMSAppender, LF5Appender, NTEventLogAppender, NullAppender, SMTPAppender, SocketAppender, SocketHubAppender, SyslogAppender, TelnetAppender, WriterAppender Widely used in many project and platforms Apache License, Version 2.0
    Java Logging API SEVERE WARNING INFO CONFIG FINE FINER FINEST Depends on the underlying framework; Sun's default Java Virtual Machine (JVM) has the following: ConsoleHandler, FileHandler, SocketHandler, MemoryHandler Not widely used[citation needed] Comes with the JRE
    Apache Commons Logging FATAL ERROR WARN INFO DEBUG TRACE Depends on the underlying framework Widely used, in conjunction with log4j Apache License, Version 2.0
    SLF4J ERROR WARN INFO DEBUG TRACE Depends on the underlying framework, which is pluggable Probably small but growing MIT License
    posted @ 2010-07-18 22:15 sevenduan 閱讀(486) | 評論 (0)編輯 收藏

    1 definition:

    “A transaction is a complete unit of work. It may comprise many computational tasks,which may include user interface, data retrieval, and communications. A typicaltransaction modifies shared resources.”

    2 transaction features:
    ACID (atomicity, consistency, isolation, durability)

    3 java spec
    JTA, JTS
     1interface javax.transaction.TransactionManager
     2{
     3public abstract void begin();
     4public abstract void commit();
     5public abstract int getStatus();
     6public abstract Transaction getTransaction();
     7public void resume(Transaction tobj);
     8public abstract void rollback();
     9public abstract void setRollbackOnly();
    10public abstract void setTransactionTimeout(intseconds);
    11public abstract Transaction suspend() ;
    12}

    4 Common XAResource
    JDBC 2.0:
    A JDBC driver that supports distributed transactions implements the javax.transaction.xa.XAResource interface, the javax.sql.XAConnectioninterface, and the  javax.sql.XADataSource interface.

    JMS 1.0:

    a JMS provider javax.transaction.xa.XAResource interface, the implements the javax.jms.XAConnection and the javax.jms.XASession interface.

    5 Common TransactionManager

    5.1 EJB Transaction Options:
    NotSupported
        If the method is called within a transaction, this transaction is suspended during the time of the method execution.
    Required
        If the method is called within a transaction, the method is executed in the scope of this transaction; otherwise, a new transaction is started for the execution of the method and committed before the method result is sent to the caller.
    RequiresNew
        The method will always be executed within the scope of a new transaction. The new transaction is started for the execution of the method, and committed before the method result is sent to the caller. If the method is called within a transaction, this transaction is suspended before the new one is started and resumed when the new transaction has completed.
    Mandatory
        The method should always be called within the scope of a transaction, else the container will throw the TransactionRequired exception.
    Supports
        The method is invoked within the caller transaction scope; if the caller does not have an associated transaction, the method is invoked without a transaction scope.
    Never
        The client is required to call the bean without any transaction context; if it is not the case, a java.rmi.RemoteException is thrown by the container.

    5.2 Spring transaction:
          Transaction isolation: The degree of isolation this transaction has from the work of other transactions. For example, can this transaction see uncommitted writes from other transactions? avaliable options:
    ISOLATION_DEFAULT
    ISOLATION_READ_UNCOMMITTED
    ISOLATION_READ_COMMITTED
    ISOLATION_REPEATABLE_READ
    ISOLATION_SERIALIZABLE

          Transaction propagation: Normally all code executed within a transaction scope will run in that transaction. However, there are several options specifying behavior if a transactional method is executed when a transaction context already exists: For example, simply running in the existing transaction (the most common case); or suspending the existing transaction and creating a new transaction. Spring offers the transaction propagation options familiar from EJB CMT. avaliable options:
    PROPAGATION_MANDATORY
    PROPAGATION_NESTED
    PROPAGATION_NEVER
    PROPAGATION_NOT_SUPPORTED
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRES_NEW
    PROPAGATION_SUPPORTS

          Transaction timeout: How long this transaction may run before timing out (automatically being rolled back by the underlying transaction infrastructure).
          Read-only status: A read-only transaction does not modify any data. Read-only transactions can be a useful optimization in some cases (such as when using Hibernate).


    6 transaction for web service
    Protocol specifications:
    WS-Transaction
    OASIS Business Transaction Protocol (BTP)
    Java API
    JAXTX (JSR-156)

     

    posted @ 2010-04-25 16:44 sevenduan 閱讀(611) | 評論 (0)編輯 收藏

    JavaScript里有兩個容易讓初學者混淆的概念:scope chain and closure。
    比如說,我想創建10個函數,每個函數依次返回0-9.
     1 //wrong: all function refer to global variable i=10 
     2 var fn_list=[];
     3 for(var i=0;i<10;i++){
     4  var _tempFn =function(){
     5         return i;
     6  }
     7  fn_list.push(_tempFn);    
     8 }
     9 //right: every function refer to its closure scope variable a
    10 var fn_list=[];
    11 for(var i=0;i<10;i++){
    12  var _tempFn =function(a){
    13         return function(){
    14          return a;
    15         };
    16  }
    17  fn_list.push(_tempFn(i));    
    18 }
    19 

    Java里也有兩個讓初學者容易混淆的概念:nest class and inner class。
    nest class就是static inner class,
    而inner class就是no-static inner class。沒有為什么,sun就是這么定義的。
    還是上面得例子,創建10個對象,每個對象的getValue接口依次返回0-9.
     1 public class Test {
     2     private int noStaticValue;
     3     private static int staticValue;
     4 
     5     public Test(int noSV, int sv) {
     6         this.noStaticValue = noSV;
     7         this.staticValue = sv;
     8     }
     9 
    10     public Test(int noSV) {
    11         this.noStaticValue = noSV;
    12     }
    13 
    14     interface valueHolder {
    15         int getValue();
    16     }
    17 
    18     class innerClass implements valueHolder {
    19         public int getValue() {
    20             return noStaticValue;
    21         }
    22     }
    23 
    24     static class nestClass implements valueHolder {
    25         public nestClass(int i) {
    26             staticValue = i;
    27         }
    28 
    29         public int getValue() {
    30             return staticValue;
    31         }
    32     }
    33 
    34     public static void main(String[] args) {
    35         Test context1 = new Test(00);
    36         valueHolder[] list = new valueHolder[10];
    37         for (int i = 0; i < 10; i++) {
    38             list[i] = new Test.nestClass(i);
    39         }
    40         for (valueHolder obj : list) {
    41             System.out.println(obj.getValue());// always print 9
    42         }
    43         for (int i = 0; i < 10; i++) {
    44             list[i] = new Test(i).new innerClass();
    45         }
    46         for (valueHolder obj : list) {
    47             System.out.println(obj.getValue());// print 0-9
    48         }
    49     }
    50 }
    可見用inner class可以模擬closure的特性,就是運行時定義class的某些狀態。
    inner class和nest class之間的區別就是后者是靜態類。前者必須通過wrap class的實例來調用new,e.g. new Test().new innerClass。
    因為nest class是靜態類,所以可以添加static member 或者static method,而inner class 不行。
    匿名內部類是inner class的一種特殊形式,所以也不能添加static member 或者static method。



    posted @ 2010-04-17 23:07 sevenduan 閱讀(2787) | 評論 (5)編輯 收藏

    先看一段代碼:
    byte [] b = new byte[]{1,-1,2,-2};
            System.out.println(Arrays.toString(
    new String(b).getBytes()));

    輸出:
    [1, -17, -65, -67, 2, -17, -65, -67]
    解釋:
    byte decode to String,String encode to byte 默認用UTF-8 charset.
    decode遇到不支持的字符 輸出 char ? , encode ? 就是 -17, -65, -67.
    實現細節可見ByteToCharUTF8.java

    解決辦法: 使用 ISO8859_1 charset。

    教訓: 注意charset的范圍。



    posted @ 2010-04-14 23:14 sevenduan 閱讀(2034) | 評論 (0)編輯 收藏

    java bitwise operator:
    ~ The unary bitwise complement operator "~" inverts a bit pattern.
    <<The signed left shift
    >>The signed right shift
    >>>the unsigned right shift

    & The bitwise & operator performs a bitwise AND operation.

    ^ The bitwise ^ operator performs a bitwise exclusive OR operation.

    | The bitwise | operator performs a bitwise inclusive OR operation.



    Usage:
    1,
    • ^ can swap two variables without using an intermediate, temporary variable which is useful if you are short on available RAM or want that sliver of extra speed.

      Usually, when not using ^, you will do:

      temp = a;

      a = b;

      b = temp;

      Using ^, no "temp" is needed:

      a ^= b;

      b ^= a;

      a ^= b;

      This will swap "a" and "b" integers. Both must be integers.

    2,
    an example of using an integer to maintain state flags (common usage):
    // These are my masks

    private static final int MASK_DID_HOMEWORK  = 0x0001;

    private static final int MASK_ATE_DINNER    = 0x0002;

    private static final int MASK_SLEPT_WELL    = 0x0004;



    // This is my current state

    private int m_nCurState;

    To set my state, I use the bitwise OR operator:

    // Set state for'ate dinner' and 'slept well' to 'on'

    m_nCurState
    = m_nCurState | (MASK_ATE_DINNER | MASK_SLEPT_WELL);

    Notice how I 'or' my current state in with the states that I want to turn 'on'. Who knows what my current state is and I don't want to blow it away.

    To unset my state, I use the bitwise AND operator with the complement operator:

    // Turn off the 'ate dinner' flag

    m_nCurState
    = (m_nCurState & ~MASK_ATE_DINNER);

    To check my current state, I use the AND operator:

    // Check if I did my homework

    if (0 != (m_nCurState & MASK_DID_HOMEWORK)) {

       
    // yep

    } else {

       
    // nope...

    }

    Why do I think this is interesting? Say I'm designing an interface that sets my state. I could write a method that accepts three booleans:

    void setState( boolean bDidHomework, boolean bAteDinner, boolean bSleptWell);

    Or, I could use a single number to represent all three states and pass a single value:

    void setState( int nStateBits);

    If you choose the second pattern you'll be very happy when decide to add another state - you won't have to break existing impls of your interface.


    posted @ 2010-04-13 14:39 sevenduan 閱讀(413) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 免费无码看av的网站| 毛片免费在线观看网站| 亚洲乱码中文字幕综合234| 亚洲综合av一区二区三区不卡| 日本zzzzwww大片免费| 噜噜噜亚洲色成人网站∨| 免费无码中文字幕A级毛片| 久久久久亚洲AV成人片| 国产精品成人观看视频免费| 亚洲成电影在线观看青青| 国产免费女女脚奴视频网| 在线综合亚洲欧洲综合网站 | 亚洲小视频在线观看| 日韩在线不卡免费视频一区| 亚洲一卡2卡三卡4卡有限公司| 亚洲毛片免费观看| 亚洲精品永久在线观看| 亚洲AV无码专区日韩| 久久久精品国产亚洲成人满18免费网站| 亚洲欧洲日产国码av系列天堂| 国内精品一级毛片免费看| 亚洲综合一区二区精品久久| 国产美女在线精品免费观看| 黄色免费在线观看网址| 亚洲一区二区三区在线观看精品中文| 久久免费福利视频| 亚洲人av高清无码| 亚洲熟妇丰满多毛XXXX| 69天堂人成无码麻豆免费视频| 亚洲av无码专区亚洲av不卡| 亚洲色大成网站www永久一区| 最近免费2019中文字幕大全| 亚洲日本VA午夜在线电影| 久久亚洲国产精品五月天婷| 69视频在线是免费观看| 色噜噜噜噜亚洲第一| 久久久久久亚洲精品中文字幕 | 全亚洲最新黄色特级网站| 久久国产免费观看精品| 亚洲熟妇无码AV| 亚洲AV无码一区二区乱子伦|