java Ïß³ÌС½á
1, ΪʲôwaitÓënotify֮ǰ±ØÐëÒª¼Ósynchronized?
´ð°¸ÆäʵºÜ¼òµ¥£¬Ò²ÊÇΪÁË·ÀÖ¹µÈ´ý-֪ͨ»úÖÆ³öÏÖrace condition
Ϊʲô»á³öÏÖrace condition ?
´ð£º ¶ÔÏóÔÚ±»wait֮ǰÒѾ±»ÁíÒ»Ïß³Ìnotify , Ö®ºóµÄwait »áÓÀ¾ÃÍ£Ö¹,²¢µ¼ÖÂdeadlock(ËÀËø)
ÀíÏëÇé¿ö£º
1, µÚÒ»¸öÏß³ÌÅжϸöÔÏóÊÇ·ñÒªwait
2, µÚÒ»¸öÏ߳̽«¶ÔÏówait
3, µÚ¶þ¸öÏß³ÌÔÙ½«¶ÔÏónotify
ʵ¼ÊÇé¿ö
1, µÚÒ»¸öÏß³ÌÅжϸöÔÏóÊÇ·ñÒªwait
2, µÚ¶þ¸öÏ߳̽«¶ÔÏónotify
3, µÚÒ»¸öÏ߳̽«¶ÔÏówait
ΪÁË·ÀÖ¹ÕâЩÇé¿ö£¬²ÅÐèÒªÔÚwaitÓënotify֮ǰ¼Ósynchronized
java ´úÂë
A a = A.getInstance();//µ¥Àý¶ÔÏó,ͬһ·ÝʵÀý²»Ïú»Ù
synchronized (a) {
a.wait();
}
-------------------------------ÁíÒ»Ïß³Ì
A a = A.getInstance();
synchronized(a) {
a.notify();
}
µÈ´ý-֪ͨ»úÖÆ±ØÐëÓësychronizedÒ»ÆðÓÃ,·ñÔò×ÔÉíÒ²»áÓÐ race condition.
2, ¾²Ì¬Í¬²½·½·¨Óë·Ç¾²Ì¬Í¬²½·½·¨µÄÇø±ð
ÓÐʱ£¬ÎÒÃǾ³£»áÅöµ½ÕâÑùµÄ´úÂ룡
ÒµÎñÂß¼µÄ·â×°Àà:
public class Logic {
private static final Log log = LogFactory.getLog(Logic.class);
private static Logic logic;
private Logic() {}
public static Logic getInstance() {
if (null == logic) {
logic = new Logic();
}
return logic;
}
public static synchronized void testStatic() {
log.info(Thread.currentThread().getName() + " : static method is running");
}
public synchronized void testNonStatic() {
log.info(Thread.currentThread().getName() + " : non static method is running");
}
}
·Ç¾²Ì¬·½·¨µÄÖ´ÐÐ:
public class ThreadRun1 extends Thread {
private static final Log log = LogFactory.getLog(ThreadRun1.class);
public void run() {
Logic logic = Logic.getInstance(); // object reference
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
log.error("some exceptions occured :", e);
}
logic.testNonStatic();
logEnd();
}
private void logEnd() {
log.info("thread ru
Ïà¹ØÎĵµ£º
JavaỊ̈߳ºÐÂÌØÕ÷-×èÈû¶ÓÁÐ
×èÈû¶ÓÁÐÊÇJava5Ïß³ÌÐÂÌØÕ÷ÖеÄÄÚÈÝ£¬Java¶¨ÒåÁË×èÈû¶ÓÁеĽӿÚjava.util.concurrent.BlockingQueue£¬×èÈû¶ÓÁеĸÅÄîÊÇ£¬Ò»¸öÖ¸¶¨³¤¶ÈµÄ¶ÓÁУ¬Èç¹û¶ÓÁÐÂúÁË£¬Ìí¼ÓÐÂÔªËØµÄ²Ù×÷»á±»×èÈûµÈ´ý£¬Ö±µ½ÓпÕλΪֹ¡£Í¬Ñù£¬µ±¶ÓÁÐΪ¿Õʱºò£¬ÇëÇó¶ÓÁÐÔªËØµÄ²Ù×÷ͬÑù»á×èÈûµÈ´ý£¬Ö±µ½ÓпÉÓÃÔªËØÎª ......
JavaỊ̈߳ºÐÂÌØÕ÷-Ìõ¼þ±äÁ¿
Ìõ¼þ±äÁ¿ÊÇJava5Ïß³ÌÖкÜÖØÒªµÄÒ»¸ö¸ÅÄ¹ËÃû˼Ò壬Ìõ¼þ±äÁ¿¾ÍÊDZíʾÌõ¼þµÄÒ»ÖÖ±äÁ¿¡£µ«ÊDZØÐë˵Ã÷£¬ÕâÀïµÄÌõ¼þÊÇûÓÐʵ¼Êº¬ÒåµÄ£¬½ö½öÊǸö±ê¼Ç¶øÒÑ£¬²¢ÇÒÌõ¼þµÄº¬ÒåÍùÍùͨ¹ý´úÂëÀ´¸³ÓèÆäº¬Òå¡£
ÕâÀïµÄÌõ¼þºÍÆÕͨÒâÒåÉϵÄÌõ¼þ±í´ïʽÓÐ×ÅÌìÈÀÖ®±ð¡£
Ìõ¼þ±äÁ¿¶¼ÊµÏÖÁË ......
¡¡¡¡6.1 »ù±¾Êý¾ÝÀàÐÍ
¡¡¡¡´«ÊÚÐÂÖª
¡¡¡¡ÔÚJavaÓïÑÔÖУ¬Êý¾ÝÀàÐÍ¿ÉÒÔ·ÖΪÁ½´óÀࣺ
¡¡¡¡1£©»ù±¾ÀàÐÍ£»
¡¡¡¡2£©À©Õ¹ÀàÐÍ¡£
¡¡¡¡ÔÚ±¾Ð¡½ÚÖУ¬ÎÒÃǾÍÒ»ÆðÀ´Ñ§Ï°Ò»ÏÂJavaÓïÑԵĻù±¾Êý¾ÝÀàÐÍ¡£Ëü°üÀ¨£ºboolean¡¢char¡¢byte¡¢int¡¢short¡¢long¡¢float¡¢double°ËÖÖ£º
¡¡¡¡ÀàÐÍ ÃèÊö ȡֵ·¶Î§
¡¡¡¡Boolean ²¼¶ûÐÍ Ö»ÓÐÁ½¸öÖµt ......
JavaÊý¾ÝÀàÐÍ
HibernateÊý¾ÝÀàÐÍ
±ê×¼SQLÊý¾ÝÀàÐÍ
(PS:¶ÔÓÚ²»Í¬µÄDB¿ÉÄÜÓÐËù²îÒì)
byte¡¢java.lang.Byte
byte
TINYINT
short¡¢java.lang.Short
short
SMALLINT
int¡¢java.lang.Integer
integer
INGEGER
long¡¢java.lang.Long
long
BIGINT
float¡¢java.lang.Float
float
FLOAT
double¡¢java.lang.Doubl ......
1, ±£Ö¤Ḭ̈߳²È«µÄÈýÖÖ·½·¨ :
a, ²»Òª¿çÏ̷߳ÃÎʹ²Ïí±äÁ¿
b, ʹ¹²Ïí±äÁ¿ÊÇ finalÀàÐ͵Ä
c, ½«¹²Ïí±äÁ¿µÄ²Ù×÷¼ÓÉÏͬ²½
2, Ò»¿ªÊ¼¾Í½«ÀàÉè¼Æ³ÉḬ̈߳²È«µÄ , ±ÈÔÚºóÆÚÖØÐÂÐÞ¸´Ëü ,¸üÈÝÒ× .
3, ±àд¶àÏ̳߳ÌÐò , Ê×Ïȱ£Ö¤ËüÊÇÕýÈ·µÄ , Æä´ÎÔÙ¿¼ÂÇÐÔÄÜ .
4, ÎÞ״̬»òÖ»¶Á¶ÔÏóÓÀÔ¶ÊÇḬ̈߳²È«µÄ .
5, ²»Òª½«Ò»¸ö¹²Ïí±äÁ¿Âã ......