??xml version="1.0" encoding="utf-8" standalone="yes"?>在线视频观看你懂的,欧美日韩精品久久久免费观看,日韩av一区二区三区美女毛片 http://www.aygfsteel.com/shijian/category/44818.htmlzh-cnMon, 19 Dec 2011 20:53:49 GMTMon, 19 Dec 2011 20:53:49 GMT60Java concurrency in practice http://www.aygfsteel.com/shijian/archive/2011/12/18/366677.html矛_同学矛_同学Sun, 18 Dec 2011 14:56:00 GMThttp://www.aygfsteel.com/shijian/archive/2011/12/18/366677.htmlhttp://www.aygfsteel.com/shijian/comments/366677.htmlhttp://www.aygfsteel.com/shijian/archive/2011/12/18/366677.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/366677.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/366677.html12?8?chapter 2 Thread Safe

1.what is thread safe ?
多个U程q发讉KӞ无需额外的同步或协调Q能保证执行的正性,则此cMؓU程安全。(l合JavaҎ,每个thread都会有独立的stackI间Q因Z在存在状态的c,才会Dthread safe问题。无状态的c,LU程安全的。)

A class is thread-safe if it behaves correctly when accessed from multiple threads, regardless of the scheduling or interleaving of the execution of those threads by the runtime environment, and with no additional synchronization or other coordination on the part of the calling code.

2.Atomicity
如:servlet通过count属性记录访问数Q此cLU程不安全的。原因是Qcount++Qƈ非原子操作;实际?个步骤,dcount、加1、写回主存,其中M阶段其它U程均可q行操作Q若count++操作时原子时Q是保证计数功能是线E安全的?br />race condition : The possibility of incorrect results in the presence of unlucky timing is so important in concurrent programming that it has a name: a race condition.

The most common type of race condition is check-then-act, where a potentially stale observation is used to make a decision on what to do next. 最常见的race condition操作Q?check-then-act' -> 'd-操作'Qlazy initQ,此时会导致用一个stale状态去军_下一步的操作。(或count++操作Qread-modify-writecdQ?br />

Both LazyInitRace and UnsafeCountingFactorizer contained a sequence of operations that needed to be atomic, or indivisible, relative to other operations on the same state. To avoid race conditions, there must be a way to prevent other threads from using a variable while we're in the middle of modifying it, so we can ensure that other threads can observe or modify the state only before we start or after we finish, but not in the middle.
什么是原子?Q一个操作,要么全部完成Q要么没有发生,不会存在中间状态?br />
3.Locking

But if we want to add more state to our servlet, can we just add more thread-safe state variables ? 必须保证相关状态操作的原子性。Java provides a built-in locking mechanism for enforcing atomicity: the synchronized block. 
Every Java object can implicitly act as a lock for purposes of synchronization。锁是属于实例的Q类U别对应的实例是Class对象。且在Q意时M有一个线E持有此锁。某U程q去被synchronized保护的代码块Q必首先获取到此锁Q否则wait直到获取此锁?/div>
3.1 Reentrancy
But because intrinsic locks are reentrant, if a thread tries to acquire a lock that it already holds, the request succeeds. 
Reentrancy is implemented by associating with each lock an acquisition count and an owning thread. 实现依赖锁被获取的次数和拥有此锁的线E?br />当每ơ获取到此锁Ӟacquisition count?Q当退出synchronizedӞcount?Q直到count?Ӟ释放此锁?/div>惌Q若synchronized是非重入的,会有什么结?Q?br />
4.Guarding state with lock
sync保证compound actions原子性;对共享变量的M操作都需要显C的去syncQ这是一个问题;
对象内徏的lock与属性ƈ没有固有的关p,内徏lock方便d建sync policyM证thread safeQ?br />一U简单的ҎQ对所有状态统一使用内徏的lockQ意味着在Q何action code path都需要去syncQ如QVectorQ?br />For every invariant that involves more than one variable, all the variables involved in that invariant must be guarded by the same lock.
滥用sync会导致性能的问题?br />
5.Liveness and Performance
sync会导致性能问题。原则:sync块尽量smallQsync操作不能分割太细。如何做Q需要从safe、simple、performance考虑?br />
Deciding how big or small to make synchronized blocks may require tradeoffs among competing design forces, including safety (which must not be compromised), simplicity, and performance.通常单性和性能是相互牵制的Q不要ؓ了性能q早的牺牲简单性(是潜在的对safe的妥协)?br />Avoid holding locks during lengthy computations or operations at risk of not completing quickly such as network or console I/O.


矛_同学 2011-12-18 22:56 发表评论
]]>信息的表C和处理http://www.aygfsteel.com/shijian/archive/2010/04/24/319285.html矛_同学矛_同学Sat, 24 Apr 2010 13:39:00 GMThttp://www.aygfsteel.com/shijian/archive/2010/04/24/319285.htmlhttp://www.aygfsteel.com/shijian/comments/319285.htmlhttp://www.aygfsteel.com/shijian/archive/2010/04/24/319285.html#Feedback0http://www.aygfsteel.com/shijian/comments/commentRss/319285.htmlhttp://www.aygfsteel.com/shijian/services/trackbacks/319285.html

计算Z二进制表C和存储信息?/span>

计算机内部数据的存储Q根据数据的Ҏ分为:

1?nbsp;无符h?/span>

2?nbsp;有符h敎ͼ补码Q?/span>

3?nbsp;点?/span>

明确的关键点Q?/span>

1?nbsp;计算机内部是通过有限的位~码一个数字,因此存在“溢出”现象Q因C的范围是有限的?/span>

2?nbsp;大多数计机使用8位的块,做ؓ最的可寻址的存储器单位?/span>

       3、不同的数据cdQ数据大是不一L。(准确的要依赖机器和编译器Q?/span>

       4、对象的地址使用字节序列中的最的地址。(|络传输、跨q_时考虑字节序的问题Q?br />

一、无W号整数

       基本?#8220;二进?#8221;表示?/span> 

二、有W号整数 --- 补码 ?span style="color:#993300">同余?/span>

       使用补码Q减法也可按加法来处理(ALU不用d现减法运)。(两个用补码表C的数据相加时候,符号位和其它位l一处理Q如果最高位(W号?/span>)有进位,则进位被舍弃。)

       最高有效位为符号位Q?/span>1负数Q?/span>0正数?Java只支持有W号整数)

三、QҎ

       划分Z个域Q?/span>1.W号  2.有效位(二进制小敎ͼ  3. 指数位(2的幂Q对点数加权)

单精度:1 = 23 =8 Q?/span> 双精?/span> Q?/span>1 = 52 = 11?/span>

       Ҏ:_ֺ有限QQ点运是不可l合和交换的?/span>

四?#8220;?#8221;概念

        “?/span>”是指一个计量系l的计数范围.如时钟等.计算Z可以看成一个计量机?/span>,它也有一个计量范?/span>,即都存在一?/span>“?/span>”.例如Q?/span>
        
旉的计量范围是0?/span>11,?/span>=12.

        表示n位的计算量范围是0?/span>2(n)-1,?/span>=2Q?/span>nQ?/span>.【注Q?/span>n表示指数?/span>
        “
?/span>”实质上是计量器?/span>“溢出的量,它的值在计量器上表示不出?/span>,计量器上只能表示出模的余?/span>.M有模的计量器,均可化减法ؓ加法q算. 例如Q?/span> 假设当前旉指向10?/span>,而准时间是6?/span>,调整旉可有以下两种拨法Q?/span>
               1
、倒拨4,卻I10-4=6
               2
、顺?/span>8时Q?/span>10+8=12+6=6
        
在以12模的pȝ?/span>,?/span>8和减4效果是一L,因此凡是?/span>4q算,都可以用?/span>8来代?/span>.
        
?/span>“?/span>”而言,8?/span>4互ؓ补数.实际上以12模的pȝ?/span>,11?/span>1,10?/span>2,9?/span>3,7?/span>5,6?/span>6都有q个Ҏ?/span>.共同的特Ҏ两者相加等于模.
        
对于计算?/span>,其概念和Ҏ完全一?/span>.n位计机,?/span>n=8, 所能表C的最大数?/span>11111111,若再?/span>1UCؓ100000000(9?/span>),但因只有8?/span>,最高位1自然丢失.又回?/span>00000000,所?/span>8位二q制pȝ的模?/span>2(8). 在这Lpȝ中减法问题也可以化成加法问题,只需把减数用相应的补数表C就可以?/span>.把补数用到计机Ҏ的处理上,是补码?br />





矛_同学 2010-04-24 21:39 发表评论
]]>
վ֩ģ壺 | ӥ̶| | пѷ| | | ɽ| Ʊ| ɽ| | ɽ| | ʯɽ| | | Ƥ| Ӷ| °Ͷ| | | | | ½| °Ͷ| ¬| | | | | | | | | º| dz| | ݰ| ϲ| ̨| | |