java nioÔÚ¶àÏ̻߳·¾³ÏµĶñÃÎÖ®ÖÕ½á
ÓÐÈË˵java nioÔÚ¶àÏ̻߳·¾³Ï±à³Ì¼òÖ±¾ÍÊǸö¶ñÃÎ,ÆäʵÄãÈç¹ûÄܰÑÎÕסjava nio APIµÄÒªÁì,Äã¾Í¿ÉÒÔ½«Ö®¼ÝÔ¦.
0. Ò»¸ö channal ¶ÔÓ¦Ò»¸öSelectionKey in the same selector.
e.g:
SelectionKey sk=sc.register(selector, SelectionKey.OP_READ, handler);
sk==sc.register(selector, SelectionKey.OP_WRITE, handler) true?
selector.select() ÿ´Î·µ»ØµÄ¶ÔͬһchannalµÄskÊÇ·ñÏàͬ?
1.channel.register(...) may block if invoked concurrently with another registration[another.register(...)] or selection operation[selector.select(...)] involving *****the same selector*****.
Õâ¸öÊÇregister·½·¨jdk srcÉϵÄÔÎÄ,
e.g:
Èç¹ûÒ»¸öselection threadÒѾÔÚselect·½·¨Éϵȴýing,ÄÇôÕâ¸öʱºòÈç¹ûÓÐÁíÒ»ÌõÏ̵߳÷ÓÃchannal.register·½·¨µÄ»°,ÄÇôËü½«±»blocking.
2.selectionKey.cancel() : The key will be removed from all of the selector's key sets during *****the next selection operation[selector.select(...)]*****.
may block briefly if invoked concurrently with a cancellation[cancel()] or selection operation[select(...)] involving ***the same selector***.
Õâ¸öÒ²ÊÇcancel·½·¨jdk srcÉϵÄÔÎÄ,
e.g:
ÄãÏȽ«Ò»¸öselectionKey.cancel(),È»ºóËæ¼´ÔÙchannel.register to the same selector,
ÔÚcancelºÍregisterÖ®¼ä,Èç¹ûûÓÐÏß³Ì(°üÀ¨µ±Ç°Ïß³Ì)½øÐÐselect²Ù×÷µÄ»°,
ÄÇô throws java.nio.channels.CancelledKeyException.
ËùÒÔ cancel-->select-->re-register.
3.if don't remove the current selectedKey from selector.selectedKeys()[Set] ½«µ¼Ö selector.select(...) not block [may be cpu 100%,specially when client cut the current channel(connection)].
e.g:
Iterator<SelectionKey> it=selector.selectedKeys().iterator();
...for/while it.hasNext()...
it.remove();<------*****must do it. or Keys' Set.clear() finally;
if remove the current selectedKey from selector.selectedKeys()[Set] but don't sk.interestOps(sk.interestOps()& (~sk.readyOps()));½«µ¼Ö selector.select(...) not block [select() not block several times, or excepted exception]
4.op_write should not be registered to the selector. &nbs
Ïà¹ØÎĵµ£º
< type="text/javascript">
document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
......
JavaÔÚJDK1.3Ö®ºó¼ÓÈëÁË¿ÉÐÖú¿ª·¢¶¯Ì¬´úÀí¹¦ÄܵÄAPI.ʹÓö¯Ì¬´úÀí£¬¿ÉÒÔʹһ¸ö´¦ÀíÕߣ¨´úÀí£©·þÎñÓÚ¸÷¸ö¶ÔÏó¡£´´½¨Ò»¸ö¶¯Ì¬´úÀíÀàÖ»ÐèʵÏÖjava.lang.reflect.InvocationHandler½Ó¿Ú¡£
ÏÂÃæ´´½¨Ò»¸ö´¦ÀíÈÕÖ¾µÄ¶¯Ì¬´úÀíÀàLogHandlerÈ¥´úÀíHelloSpeakerÀà
Ê×ÏÈ´´½¨HelloSpeakerµÄ½Ó¿Ú
pa ......
¸ø Java SE ×¢Èë½Å±¾ÓïÑԵĻîÁ¦
Mustang µÄ½Å±¾ÓïÑÔÐÂÌØÐÔ
ÎĵµÑ¡Ïî
½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ
½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ
¼¶±ð£º Öм¶
Îâ 玥ò« (wuyuehao@cn.ibm.com), Èí¼þ¹¤³Ìʦ, IBM
2006 Äê 10 ÔÂ 30 ÈÕ
ÔÚ¼´½«·¢²¼µÄ Java SE6£¨Mustang£©ÖУ¬Ôö¼ÓÁ˶Խű¾ÓïÑÔµÄÖ§³Ö¡£Í¨¹ý¶Ô½Å± ......
¡¡¡¡(1) ÀàÃûÊ××ÖĸӦ¸Ã´óд¡£×ֶΡ¢·½·¨ÒÔ¼°¶ÔÏó(¾ä±ú)µÄÊ××ÖĸӦСд¡£¶ÔÓÚËùÓбêʶ·û£¬ÆäÖаüº¬µÄËùÓе¥´Ê¶¼Ó¦½ô¿¿ÔÚÒ»Æð£¬¶øÇÒ´óдÖм䵥´ÊµÄÊ××Öĸ¡£ÀýÈ磺
¡¡¡¡ThisIsAClassName
¡¡¡¡thisIsMethodOrFieldName
¡¡¡¡ÈôÔÚ¶¨ÒåÖгöÏÖÁ˳£Êý³õʼ»¯×Ö·û£¬Ôò´óдstatic final»ù±¾ÀàÐͱêʶ·ûÖеÄËùÓÐ×Öĸ¡£ÕâÑù±ã¿É±êÖ¾³öË ......
¡¡¡¡Í¨³£ÔÚÓÃJAVA¿ª·¢Èí¼þµÄ¹ý³ÌÖУ¬ÎÒÃdz£³£»áÓöµ½ÐèÒª°ÑһЩϵͳµÄÅäÖòÎÊý±£´æµ½Êý¾Ý¿âÖÐÒÔ·ÀÖ¹¶ªÊ§£¬´«Í³µÄ·½·¨Êǽ«Ã¿¸öÅäÖòÎÊý×÷Ϊ¶ÔÏóÀ´½¨Á¢Êý¾Ý¿âÄ£ÐÍ£¬Ï൱ÓÚ°ÑÄ£ÐÍÖеĶÔÏó°ó¶¨µ½Êý¾Ý±íµÄÿ¸ö×Ö¶ÎÉÏ£¬µ«ÕâÑù×öµÄ»°Áé»î¶ÈÌ«µÍ£¬µ±ÐèÒªÌí¼ÓÅäÖòÎÊýʱÏȵÃÍùÊý¾Ý±íÌí¼Ó×ֶΣ¬ÔÙÐÞ¸ÄÊý¾Ý¿âÄ£ÐͺÍÏà¹ØµÄÓ³ÉäÎļþ¡£ÄÜ·ñ ......