javaÖÐyield(),sleep()ÒÔ¼°wait()µÄÇø±ð
ÍùÍù»ìÏýÁËÕâÈý¸öº¯ÊýµÄʹÓá£
´Ó²Ù×÷ϵͳµÄ½Ç¶È½²£¬os»áά»¤Ò»¸öready queue£¨¾ÍÐ÷µÄÏ̶߳ÓÁУ©¡£²¢ÇÒÔÚijһʱ¿ÌcpuֻΪready queueÖÐλÓÚ¶ÓÁÐÍ·²¿µÄÏ̷߳þÎñ¡£
µ«Êǵ±Ç°ÕýÔÚ±»·þÎñµÄÏ߳̿ÉÄܾõµÃcpuµÄ·þÎñÖÊÁ¿²»¹»ºÃ£¬ÓÚÊÇÌáǰÍ˳ö£¬Õâ¾ÍÊÇyield¡£
»òÕßµ±Ç°ÕýÔÚ±»·þÎñµÄÏß³ÌÐèҪ˯һ»á£¬ÐÑÀ´ºó¼ÌÐø±»·þÎñ£¬Õâ¾ÍÊÇsleep¡£
sleep·½·¨²»ÍƼöʹÓ㬿ÉÓÃwait¡£
Ïß³ÌÍ˳ö×îºÃ×Ô¼ºÊµÏÖ£¬ÔÚÔËÐÐ״̬ÖÐÒ»Ö±¼ìÑéÒ»¸ö״̬£¬Èç¹ûÕâ¸ö×´Ì¬ÎªÕæ£¬¾ÍÒ»Ö±ÔËÐУ¬Èç¹ûÍâ½ç¸ü¸ÄÁËÕâ¸ö״̬±äÁ¿£¬ÄÇôÏ߳̾ÍÍ£Ö¹ÔËÐС£
sleep()ʹµ±Ç°Ï߳̽øÈëÍ£ÖÍ״̬£¬ËùÒÔÖ´ÐÐsleep()µÄÏß³ÌÔÚÖ¸¶¨µÄʱ¼äÄڿ϶¨²»»áÖ´ÐУ»yield()Ö»ÊÇʹµ±Ç°Ïß³ÌÖØÐ»ص½¿ÉÖ´ÐÐ״̬£¬ËùÒÔÖ´ÐÐyield()µÄÏß³ÌÓпÉÄÜÔÚ½øÈëµ½¿ÉÖ´ÐÐ״̬ºóÂíÉÏÓÖ±»Ö´ÐС£
sleep()¿ÉʹÓÅÏȼ¶µÍµÄÏ̵߳õ½Ö´ÐеĻú»á£¬µ±È»Ò²¿ÉÒÔÈÃͬÓÅÏȼ¶ºÍ¸ßÓÅÏȼ¶µÄÏß³ÌÓÐÖ´ÐеĻú»á£»yield()Ö»ÄÜʹͬÓÅÏȼ¶µÄÏß³ÌÓÐÖ´ÐеĻú»á¡£
µ±µ÷ÓÃwait()ºó£¬Ï̻߳áÊͷŵôËüËùÕ¼ÓÐµÄ“Ëø±êÖ¾”£¬´Ó¶øÊ¹Ïß³ÌËùÔÚ¶ÔÏóÖÐµÄÆäËüsynchronizedÊý¾Ý¿É±»±ðµÄÏß³ÌʹÓá£
waite()ºÍnotify()ÒòΪ»á¶Ô¶ÔÏóµÄ“Ëø±êÖ¾”½øÐвÙ×÷£¬ËùÒÔËüÃDZØÐëÔÚsynchronizedº¯Êý»òsynchronized¡¡blockÖнøÐе÷Óá£Èç¹ûÔÚnon-synchronizedº¯Êý»ònon-synchronized¡¡blockÖнøÐе÷Óã¬ËäÈ»ÄܱàÒëͨ¹ý£¬µ«ÔÚÔËÐÐʱ»á·¢ÉúIllegalMonitorStateExceptionµÄÒì³£¡£
³¹µ×Ã÷°×¶àÏß³ÌͨÐÅ»úÖÆ£º
Ï̼߳äµÄͨÐÅ
1. Ï̵߳ļ¸ÖÖ״̬
Ïß³ÌÓÐËÄÖÖ״̬£¬ÈκÎÒ»¸öÏ߳̿϶¨´¦ÓÚÕâËÄÖÖ״̬ÖеÄÒ»ÖÖ£º
1) ²úÉú£¨New£©£ºÏ̶߳ÔÏóÒѾ²úÉú£¬µ«ÉÐδ±»Æô¶¯£¬ËùÒÔÎÞ·¨Ö´ÐС£Èçͨ¹ýnew²úÉúÁËÒ»¸öÏ̶߳ÔÏóºóû¶ÔËüµ÷ÓÃstart()º¯Êý֮ǰ¡£
2) ¿ÉÖ´ÐУ¨Runnable£©£ºÃ¿¸öÖ§³Ö¶àÏ̵߳Äϵͳ¶¼ÓÐÒ»¸öÅÅ³ÌÆ÷£¬ÅÅ³ÌÆ÷»á´ÓÏ̳߳ØÖÐÑ¡ÔñÒ»¸öÏ̲߳¢Æô¶¯Ëü¡£µ±Ò»¸öÏ̴߳¦ÓÚ¿ÉÖ´ÐÐ״̬ʱ£¬±íʾËü¿ÉÄÜÕý´¦ÓÚÏ̳߳ØÖеȴýÅÅÅÅ³ÌÆ÷Æô¶¯Ëü£»Ò²¿ÉÄÜËüÒÑÕýÔÚÖ´ÐС£ÈçÖ´ÐÐÁËÒ»¸öÏ̶߳ÔÏóµÄstart()·½·¨ºó£¬Ï߳̾ʹ¦ÓÚ¿ÉÖ´ÐÐ״̬£¬µ«ÏÔ¶øÒ×¼ûµÄÊÇ´ËʱÏ̲߳»Ò»¶¨ÕýÔÚÖ´ÐÐÖС£
3) ËÀÍö£¨Dead£©£ºµ±Ò»¸öÏß³ÌÕý³£½áÊø£¬Ëü±ã´¦ÓÚËÀÍö״̬¡£ÈçÒ»¸öÏ̵߳Ärun()º¯ÊýÖ´ÐÐÍê±ÏºóÏ߳̾ͽøÈëËÀÍö״̬¡£
4) Í£ÖÍ£¨Blocked£©£ºµ±Ò»¸öÏ̴߳¦ÓÚÍ£ÖÍ״̬ʱ£¬ÏµÍ³ÅÅ³ÌÆ÷
Ïà¹ØÎĵµ£º
±¾ÎÄÊÇÓÉJRÖ÷³Öд×÷µÄ¡¶J2SE½ø½×¡·Ò»ÊéµÄ²¿·ÖÕ½ÚÕûÀí¶ø³É£¬¡¶J2SE½ø½×¡·ÕýÔÚд×÷¡¢ÍêÉÆ½×¶Î¡£ÄúÔĶÁºó£¬ÓÐÈκν¨Òé¡¢ÅúÆÀ£¬ÇëºÍÎÒÁªÏµ£¬»òÔÚhttp://www.javaresearch.org/forum/thread.jsp?column=376&thread=7576' target='_blank' class='l2'>Õâ¶ùÁôÑÔ¡£¡¶J2SE½ø½×¡·Ð´×÷ÏîÄ¿×é¸ÐлÄúÔĶÁ±¾ÎÄ¡£
ÔÚµ±½ñÕ ......
2009-11-23
Ö§³Ö³£¼ûµÄÊý¾ÝÀàÐ͵ÄÓ³Éä Java ÀàÐÍ C ÀàÐÍ & ......
Õâ¸öÎÊÌâ½ñÌìÖÕÓÚ¿´Ò»¸ö¸çÃǶùµÄÎÄÕ¸㶨ÁË£¬ÔÚ´Ëлл£¡ËùÒÔ×ªÔØÒ»ÏÂ
=============================================================
java-package°üµÄʹÓ÷½·¨
¡¡¡¡
µ±Ò»¸ö´óÐͳÌÐò½»ÓÉÊý¸ö²»Í¬µÄ³ÌÐòÈËÔ±¿ª·¢Ê±£¬Óõ½ÏàͬµÄÀàÃûÊǺÜÓпÉÄܵģ¬ÄÇôÈç¹û·¢ÉúÁËÕâÑùµÄʼþÎÒÃǸÃÔõô°ìÄÇ£¿£¬ÔÚÎÒÃÇjava³ÌÐò¿ª ......
Ò»¸ö¼òµ¥Ê¾Àý--
1£¬×¼±¸£ºMySQLÊý¾Ý¿âÇý¶¯°ü¡¾mysql-connector-java-5.1.10-bin.jar¡¿µ¼Èë
2£¬´´½¨²âÊÔÁ¬½ÓÖ÷³ÌÐò
package mysqlConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class JdbcDemo {
public static void main(String[] args) {
......