JAVA ¹²ÏíËøºÍÌõ¼þ±äÁ¿Ò»¶þ
¶àÏß³ÌÖ®¼äÐèҪе÷¹¤×÷¡£ÀýÈ磬ä¯ÀÀÆ÷µÄÒ»¸öÏÔʾͼƬµÄÏß³ÌdisplayThreadÏëÒªÖ´ÐÐÏÔʾͼƬµÄÈÎÎñ£¬±ØÐëµÈ´ýÏÂÔØÏß³ÌdownloadThread½«¸ÃͼƬÏÂÔØÍê±Ï¡£Èç¹ûͼƬ»¹Ã»ÓÐÏÂÔØÍ꣬displayThread¿ÉÒÔÔÝÍ££¬µ±downloadThreadÍê³ÉÁËÈÎÎñºó£¬ÔÙ֪ͨdisplayThread“ͼƬ׼±¸Íê±Ï£¬¿ÉÒÔÏÔʾÁË”£¬Õâʱ£¬displayThread¼ÌÐøÖ´ÐС£
ÒÔÉÏÂß¼¼òµ¥µÄ˵¾ÍÊÇ£ºÈç¹ûÌõ¼þ²»Âú×㣬ÔòµÈ´ý¡£µ±Ìõ¼þÂú×ãʱ£¬µÈ´ý¸ÃÌõ¼þµÄÏ߳̽«±»»½ÐÑ¡£ÔÚJavaÖУ¬Õâ¸ö»úÖÆµÄʵÏÖÒÀÀµÓÚwait/notify¡£µÈ´ý»úÖÆÓëËø»úÖÆÊÇÃÜÇйØÁªµÄ¡£ÀýÈ磺
synchronized(obj) {
while(!condition) {
obj.wait();
}
obj.doSomething();
}
µ±Ïß³ÌA»ñµÃÁËobjËøºó£¬·¢ÏÖÌõ¼þcondition²»Âú×㣬ÎÞ·¨¼ÌÐøÏÂÒ»´¦Àí£¬ÓÚÊÇÏß³ÌA¾Íwait()¡£
ÔÚÁíÒ»Ïß³ÌBÖУ¬Èç¹ûB¸ü¸ÄÁËijЩÌõ¼þ£¬Ê¹µÃÏß³ÌAµÄconditionÌõ¼þÂú×ãÁË£¬¾Í¿ÉÒÔ»½ÐÑÏß³ÌA£º
synchronized(obj) {
condition = true;
obj.notify();
}
ÐèҪעÒâµÄ¸ÅÄîÊÇ£º
# µ÷ÓÃobjµÄwait(), notify()·½·¨Ç°£¬±ØÐë»ñµÃobjËø£¬Ò²¾ÍÊDZØÐëдÔÚsynchronized(obj) {...} ´úÂë¶ÎÄÚ¡£
# µ÷ÓÃobj.wait()ºó£¬Ïß³ÌA¾ÍÊÍ·ÅÁËobjµÄËø£¬·ñÔòÏß³ÌBÎÞ·¨»ñµÃobjËø£¬Ò²¾ÍÎÞ·¨ÔÚsynchronized(obj) {...} ´úÂë¶ÎÄÚ»½ÐÑA¡£
# µ±obj.wait()·½·¨·µ»Øºó£¬Ïß³ÌAÐèÒªÔٴλñµÃobjËø£¬²ÅÄܼÌÐøÖ´ÐС£
# Èç¹ûA1,A2,A3¶¼ÔÚobj.wait()£¬ÔòBµ÷ÓÃobj.notify()Ö»ÄÜ»½ÐÑA1,A2,A3ÖеÄÒ»¸ö£¨¾ßÌåÄÄÒ»¸öÓÉJVM¾ö¶¨£©¡£
# obj.notifyAll()ÔòÄÜÈ«²¿»½ÐÑA1,A2,A3£¬µ«ÊÇÒª¼ÌÐøÖ´ÐÐobj.wait()µÄÏÂÒ»ÌõÓï¾ä£¬±ØÐë»ñµÃobjËø£¬Òò´Ë£¬A1,A2,A3Ö»ÓÐÒ»¸öÓлú»á»ñµÃËø¼ÌÐøÖ´ÐУ¬ÀýÈçA1£¬ÆäÓàµÄÐèÒªµÈ´ýA1ÊÍ·ÅobjËøÖ®ºó²ÅÄܼÌÐøÖ´ÐС£
# µ±Bµ÷ÓÃobj.notify/notifyAllµÄʱºò£¬BÕý³ÖÓÐobjËø£¬Òò´Ë£¬A1,A2,A3Ëä±»»½ÐÑ£¬µ«ÊÇÈÔÎÞ·¨»ñµÃobjËø¡£Ö±µ½BÍ˳ösynchronized¿é£¬ÊÍ·ÅobjËøºó£¬A1,A2,A3ÖеÄÒ»¸ö²ÅÓлú»á»ñµÃËø¼ÌÐøÖ´ÐС£
synchronizedµÄ4ÖÖÓ÷¨
1.·½·¨ÉùÃ÷ʱʹÓÃ,·ÅÔÚ·¶Î§²Ù×÷·û(publicµÈ)Ö®ºó,·µ»ØÀàÐÍÉùÃ÷(voidµÈ)֮ǰ.¼´Ò»´ÎÖ»ÄÜÓÐÒ»¸öÏ߳̽øÈë¸Ã·½·¨,ÆäËûÏß³ÌÒªÏëÔÚ´Ëʱµ÷Óø÷½·¨,Ö»ÄÜÅŶӵȺò,µ±Ç°Ïß³Ì(¾ÍÊÇÔÚsynchronized·½·¨ÄÚ²¿µÄÏß³Ì)Ö´ÐÐÍê¸Ã·½·¨ºó,±ðµÄÏ̲߳ÅÄܽøÈë.
ÀýÈç:
&nbs
Ïà¹ØÎĵµ£º
package game;
public class HanTa {
public static int i = 0;
public static void main(String[] args){
calc('A', 'B', 'C', 2);
System.out.println("×îÉÙÐèÒª"+i+"²½¡£");
}
//ººÂÞËþÓÎÏ·¼ÆËã
public static void calc(char src, char ilde, c ......
JavaÊý¾ÝÀàÐÍÓëת»»
JavaÊý¾ÝÀàÐÍ·ÖΪÈý´óÀà
²¼¶ûÐÍ£¬×Ö·ûÐÍ(char)£¬ÊýÖµÐÍ(ÕûÊý,¸¡µãÐÍ)
ÕûÊýÀàÐÍÓУºbyte(8bits)¡¢short(16bits)¡¢int(32bits)¡¢long(64bits)¡¢
¸¡µãÀàÐÍÓУºµ¥¾«¶È£¨32bits float£©¡¢Ë«¾«¶È£¨64bits double£©
booleanÀàÐͱäÁ¿µÄȡֵÓУºture¡¢false
charÊý¾ÝÀàÐÍÓУºunicode×Ö·û,16λ
Êý¾ÝÀàÐÍת» ......
package game;
public class HanTaGame {
public static void main(String[] args) {
fun('1', '2', '3', 2);
}
// ººËþÓÎÏ·½â¾ö·½°¸
public static void fun(char src, char idle, char dest, int n) {
if (1 == n) {
System.out.println(src ......
19.1.1. Spring¶Ôlog4jµÄ¼¸¸öÔöÇ¿
×¢Òâ
¸öÈ˽¨Òé¶¼²»ÒªÊ¹Óá£
¶¨Ê±Ë¢ÐÂlog4j.properties£¬ÎÞÐëÖØÆô·þÎñÆ÷¸üÐÂlog4jÉèÖá£ËäÈ»ÕâÊǸöJ2EE Best
Practice£¬µ«ÔÚSpringµÄJavaDocÀï×¢Ã÷Á˲»ÍƼöÓÃÓÚÉú²ú»·¾³£¬ÒòΪ·þÎñÆ÷ÖØÆôµÄʱºò£¬ÄÇÌõwatch thread²»»á¹Ø±Õ¡£
½«
log4j.propertiesÎļþ·ÅÔÚWEB-INF/log4j.properti ......
×î½üһֱдjava ²Ù×÷¶ÌÐÅèµÄapp.
ºóÀ´google µ½smslib £¬²»´íµÄopensource.libraray.
ÔÚÍøÉÏҲûÕÒµ½ÖÐÎĵģ¬
ÓÚÊÇ·ÒëµÄÒ»ÏÂsmslib µÄ¼ò½é
Smslib ÊÇÒ»¸öÔÊÐíÄãͨ¹ýÒ»¸ögsm Modem »òÕßÊÇÒ»¸ö gsm phoneÊÕ·¢¶ÌÐŵÄjava ¿â.(Open source)
Smslib ×îа汾ÊÇ3.4.6.
Smslib v3 ÒÀÈ»±£ÁôÁËһЩÒÔǰµÄ¹¦ÄÜ ......