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

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

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

    七段

    無(wú)論怎樣,請(qǐng)讓我先感謝一下國(guó)家。

    BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
      35 Posts :: 2 Stories :: 7 Comments :: 0 Trackbacks

    #

    有25匹馬,每匹馬都以一個(gè)固定不變的速度奔跑,每匹馬的速度都不一樣,如果讓你找出跑的最快的5匹馬,最少需要組織多少場(chǎng)比賽?注:每場(chǎng)比賽最多只能5匹馬參賽。
    re:悲觀10場(chǎng),樂(lè)觀7場(chǎng)。
    posted @ 2012-03-07 21:17 sevenduan 閱讀(836) | 評(píng)論 (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 閱讀(256) | 評(píng)論 (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 閱讀(492) | 評(píng)論 (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 閱讀(617) | 評(píng)論 (0)編輯 收藏

    JavaScript里有兩個(gè)容易讓初學(xué)者混淆的概念:scope chain and closure。
    比如說(shuō),我想創(chuàng)建10個(gè)函數(shù),每個(gè)函數(shù)依次返回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里也有兩個(gè)讓初學(xué)者容易混淆的概念:nest class and inner class。
    nest class就是static inner class,
    而inner class就是no-static inner class。沒(méi)有為什么,sun就是這么定義的。
    還是上面得例子,創(chuàng)建10個(gè)對(duì)象,每個(gè)對(duì)象的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 }
    可見(jiàn)用inner class可以模擬closure的特性,就是運(yùn)行時(shí)定義class的某些狀態(tài)。
    inner class和nest class之間的區(qū)別就是后者是靜態(tài)類。前者必須通過(guò)wrap class的實(shí)例來(lái)調(diào)用new,e.g. new Test().new innerClass。
    因?yàn)閚est class是靜態(tài)類,所以可以添加static member 或者static method,而inner class 不行。
    匿名內(nèi)部類是inner class的一種特殊形式,所以也不能添加static member 或者static method。



    posted @ 2010-04-17 23:07 sevenduan 閱讀(2794) | 評(píng)論 (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 默認(rèn)用UTF-8 charset.
    decode遇到不支持的字符 輸出 char ? , encode ? 就是 -17, -65, -67.
    實(shí)現(xiàn)細(xì)節(jié)可見(jiàn)ByteToCharUTF8.java

    解決辦法: 使用 ISO8859_1 charset。

    教訓(xùn): 注意charset的范圍。



    posted @ 2010-04-14 23:14 sevenduan 閱讀(2041) | 評(píng)論 (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 閱讀(419) | 評(píng)論 (0)編輯 收藏

    什么才是激勵(lì)你工作的動(dòng)力?
    這個(gè)問(wèn)題問(wèn)自己的往往很少。經(jīng)常思考這些問(wèn)題的往往是管理者。當(dāng)管理者想進(jìn)行一些管理工作的時(shí)候,管理本身就成了最大的問(wèn)題。所以,一個(gè)項(xiàng)目的成敗往往在很大程度上取決于受到管理層的負(fù)面影響的大小。
    大多數(shù)人和大多數(shù)管理者有著共同的認(rèn)識(shí),錢才是激勵(lì)我們工作的動(dòng)力。理由很充分,盈利是企業(yè)的唯一目標(biāo),說(shuō)起來(lái)就好像人活著就是為了吃飯一樣。所以,各種績(jī)效考核與薪酬掛鉤了,各種項(xiàng)目獎(jiǎng)、季度獎(jiǎng)、年終獎(jiǎng)?wù)Q生了。為了響應(yīng)上級(jí)政策,我們開始加班加點(diǎn)了,開始趕進(jìn)度趕業(yè)績(jī)了。試想,在這種驅(qū)動(dòng)下,如果手頭的事情沒(méi)有和獎(jiǎng)金掛鉤,你還有動(dòng)力繼續(xù)么?
    結(jié)果唯一導(dǎo)向?qū)τ谥貜?fù)性的體力勞動(dòng)來(lái)說(shuō)是有效的。但是對(duì)于腦力勞動(dòng)者來(lái)說(shuō),自發(fā)、專精和目標(biāo)性才是內(nèi)在的能夠持續(xù)激勵(lì)我們工作的動(dòng)力所在。
    自發(fā):
    對(duì)于腦力勞動(dòng),命令式的分配任務(wù)很難奏效,很顯然,你不能強(qiáng)迫別人的想法。就像強(qiáng)迫學(xué)生學(xué)習(xí)一樣。只有自發(fā)的工作,才能培養(yǎng)興趣激發(fā)工作熱情。正如敏捷實(shí)踐里強(qiáng)調(diào)任務(wù)應(yīng)該由個(gè)人自發(fā)選擇領(lǐng)取一樣。
    專精:
    在自發(fā)的前提下,無(wú)論我們做什么事情,我們總是希望自己可以做得更好。這就是專精。對(duì)專精的向往表現(xiàn)為對(duì)工作的癡迷。要想更為專精,必須不斷的練習(xí)實(shí)踐和分析思考。
    目標(biāo)性:
    自發(fā)和專精也許能在中短期維持動(dòng)力,但是長(zhǎng)期下去,當(dāng)我們不知道自己為什么工作的時(shí)候,動(dòng)力也會(huì)衰竭。目標(biāo)性要求目標(biāo)不能太低而沒(méi)有成就感,或者太高而很難達(dá)到。最好的目標(biāo)是比你現(xiàn)在的成就更高,且需要一定的努力才能達(dá)到。
    Drive: The Surprising Truth About What Motivates Us


    posted @ 2010-04-05 23:43 sevenduan 閱讀(507) | 評(píng)論 (0)編輯 收藏

    簡(jiǎn)便個(gè)人項(xiàng)目管理:
    1,一周一個(gè)iteration,一個(gè)iteration共計(jì)30個(gè)man hours:
    只要可以小迭代總是更好。
    story point優(yōu)勢(shì)在于消除個(gè)體差異,個(gè)人項(xiàng)目man hour更準(zhǔn)確直接。
    2, 每周日做iteration plan,計(jì)劃下周任務(wù),用gmail tasks來(lái)做story wall。
    3,每周五晚做retrospective,總結(jié)一周工作,直接用gmail來(lái)保存回顧總結(jié)。

    posted @ 2010-04-01 00:54 sevenduan 閱讀(251) | 評(píng)論 (0)編輯 收藏

    Ref: http://community.jboss.org/wiki/JBossCacheOfficialDocumentation

    Cache的目的是為了以空間換時(shí)間,一次計(jì)算結(jié)果為多次重用。
    空間可以是實(shí)時(shí)內(nèi)存空間、持久化的硬盤空間。時(shí)間可以是運(yùn)算時(shí)間、連接時(shí)間、傳輸時(shí)間等。

    Cache可以分為L(zhǎng)ocalCache和DistributedCache。
    最簡(jiǎn)單的LocalCache可以通過(guò)維護(hù)一個(gè)ConcurrentHashMap實(shí)現(xiàn)。
    缺點(diǎn)是:
    1,內(nèi)存有限,容易o(hù)ut of memory (定期清除?持久化?)
    2, 需要對(duì)全map做concurrency維護(hù),粗粒度的鎖定爭(zhēng)用會(huì)影響性能(樹結(jié)構(gòu)維護(hù)?)

    在一個(gè)專業(yè)的企業(yè)級(jí)應(yīng)用中,cache除了高性能和線程安全的要求,還要支持事務(wù)、高可用性、持久化、容錯(cuò)、集群同步等。
    JBossCache是一個(gè)典型的企業(yè)級(jí)cache實(shí)現(xiàn),他采用樹結(jié)構(gòu)且支持集群和事務(wù)特性。
    雖然JBossCache這把牛刀也可以在standalone的JS2E應(yīng)用中用來(lái)殺雞,但我們應(yīng)該更關(guān)心用他在集群環(huán)境中怎么殺牛。
    JBossCache分為非集群模式(Local)和集群模式。
    集群模式根據(jù)實(shí)現(xiàn)策略又分為replication和invalidation。
    1 replication:通過(guò)拷貝改變的cache對(duì)象來(lái)保證與集群中其他cache同步。replication又可細(xì)分為同步replication和異步repliation兩種,異步replication較快,put以后馬上返回,但是replication出錯(cuò)了,事務(wù)還是算完成了不回回滾。同步replication要花時(shí)間等待其他的cache完成replication的通知才能結(jié)束。

    2 invalidation: 如果cache狀態(tài)改變,僅僅是給其他cache發(fā)個(gè)通知,收到通知的cache把臟數(shù)據(jù)清除掉。invalidation也可分為同步和異步兩種,區(qū)別是發(fā)送通知的廣播方式一個(gè)是同步一個(gè)是異步。

    在jboss cluster中,我們最好通過(guò)MBean來(lái)部署jboss cache。這樣又幾個(gè)好處:
    1,JBoss NS支持Cluster
    我們就可以通過(guò)JBoss NamingService來(lái)訪問(wèn)cache。如果在local NS中查不到cache,jbss NS還會(huì)去查cluster中其他的cache。
    2,利用MBean的特性
    通過(guò)CacheMBean, 我們可以方便的管理Cache Service,實(shí)時(shí)的啟動(dòng)、停止或者改變一些配置,還可以監(jiān)控到一些cache統(tǒng)計(jì)數(shù)據(jù)。
    3,利用microcontainer的特性
    我們可以通過(guò)配置XML文件來(lái)完成cache相關(guān)的所有對(duì)象聲明。簡(jiǎn)而言之,就是利用java reflection和AOP的技術(shù)就不用寫聲明cache的代碼了。


    <?xml version="1.0" encoding="UTF-8"?>



    <deployment xmlns="urn:jboss:bean-deployer:2.0">



       
    <!-- First we create a Configuration object for the cache -->

       
    <bean name="ExampleCacheConfig"

             class
    ="org.jboss.cache.config.Configuration">

          

           build up the Configuration

          

       
    </bean>

       

       
    <!-- Factory to build the Cache. -->

       
    <bean name="DefaultCacheFactory" class="org.jboss.cache.DefaultCacheFactory">      

          
    <constructor factoryClass="org.jboss.cache.DefaultCacheFactory"

                       factoryMethod
    ="getInstance" />

       
    </bean>

       

       
    <!-- The cache itself -->

       
    <bean name="ExampleCache" class="org.jboss.cache.CacheImpl">

          

          
    <constructor factoryMethod="createnewInstance">

              
    <factory bean="DefaultCacheFactory"/>

              
    <parameter><inject bean="ExampleCacheConfig"/></parameter>

              
    <parameter>false</parameter>

          
    </constructor>

              

       
    </bean>

       

       
    <!-- JMX Management -->

       
    <bean name="ExampleCacheJmxWrapper" class="org.jboss.cache.jmx.CacheJmxWrapper">

          

          
    <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.cache:service=ExampleTreeCache", 

                             exposedInterface=org.jboss.cache.jmx.CacheJmxWrapperMBean.class, 

                             registerDirectly=true)
    </annotation>

          

          
    <constructor>

              
    <parameter><inject bean="ExampleCache"/></parameter>

          
    </constructor>

              

       
    </bean>



    </deployment> 

    后記:
    1,jboss cache的naga版中,采用Multi-versioned concurrency control來(lái)實(shí)現(xiàn)并發(fā)。下次再?gòu)闹锌偨Y(jié)一下多線程的學(xué)習(xí)。
    2,jboss cache通過(guò)結(jié)合visitor pattern和command pattern,把對(duì)cache node的操作與訪問(wèn)從中隔離出來(lái),不用改變或者擴(kuò)展node對(duì)象就可以添加新的node行為。也就是開閉原則。下次再?gòu)闹锌偨Y(jié)一下幾種設(shè)計(jì)模式的經(jīng)典應(yīng)用。



    posted @ 2010-03-28 23:10 sevenduan 閱讀(2511) | 評(píng)論 (0)編輯 收藏

    僅列出標(biāo)題
    共4頁(yè): 1 2 3 4 下一頁(yè) 
    主站蜘蛛池模板: 四虎成人精品一区二区免费网站| 又大又硬又粗又黄的视频免费看| 在线观看片免费人成视频无码 | 国产成人综合亚洲绿色| 成年人网站在线免费观看| 亚洲jjzzjjzz在线播放| 成人黄色免费网站| 亚洲一区二区影视| 大地资源二在线观看免费高清| 国产精品亚洲精品观看不卡| 久久不见久久见中文字幕免费| 国产午夜亚洲精品国产| 国产成人高清精品免费软件 | 亚洲综合国产一区二区三区| g0g0人体全免费高清大胆视频| 亚洲日韩在线中文字幕第一页| 中文字幕免费在线观看动作大片| 亚洲免费观看视频| 91视频免费网址| 亚洲一区二区三区乱码在线欧洲| 青青草国产免费久久久下载| 男男gay做爽爽的视频免费| 2022中文字字幕久亚洲| 久久国产乱子免费精品| 亚洲国产精品成人精品软件| 毛片免费视频播放| 永久免费无码日韩视频| 亚洲嫩草影院久久精品| 久久久久国色AV免费观看性色| 国产精品亚洲专区无码唯爱网| 国产亚洲情侣一区二区无码AV | 亚洲成a∨人片在无码2023| 免费一区二区三区四区五区 | 久久精品无码专区免费| 亚洲AV无码久久精品色欲| 免费视频专区一国产盗摄| 国产成人亚洲综合在线| 亚洲国产综合专区在线电影 | 91视频国产免费| 一区二区3区免费视频| 亚洲高清视频在线播放|