java¶àÏß³ÌʹÓÃSynchronized¹Ø¼ü×Öͬ²½Àà·½
ÒªÏë½â¾ö“ÔàÊý¾Ý”µÄÎÊÌ⣬×î¼òµ¥µÄ·½·¨¾ÍÊÇʹÓÃsynchronized¹Ø¼ü×ÖÀ´Ê¹run·½·¨Í¬²½£¬´úÂëÈçÏ£º
public synchronized void run()
{
}
´ÓÉÏÃæµÄ´úÂë¿ÉÒÔ¿´³ö£¬Ö»ÒªÔÚvoidºÍpublicÖ®¼ä¼ÓÉÏsynchronized¹Ø¼ü×Ö£¬¾Í¿ÉÒÔʹrun·½·¨Í¬²½£¬Ò²¾ÍÊÇ˵£¬¶ÔÓÚͬһ¸öJavaÀàµÄ¶ÔÏóʵÀý£¬run·½·¨Í¬Ê±Ö»Äܱ»Ò»¸öÏ̵߳÷Ó㬲¢µ±Ç°µÄrunÖ´ÐÐÍêºó£¬²ÅÄܱ»ÆäËûµÄÏ̵߳÷Ó᣼´Ê¹µ±Ç°Ïß³ÌÖ´Ðе½ÁËrun·½·¨ÖеÄyield·½·¨£¬Ò²Ö»ÊÇÔÝÍ£ÁËһϡ£ÓÉÓÚÆäËûÏß³ÌÎÞ·¨Ö´ÐÐrun·½·¨£¬Òò´Ë£¬×îÖÕ»¹ÊÇ»áÓɵ±Ç°µÄÏß³ÌÀ´¼ÌÐøÖ´ÐС£ÏÈ¿´¿´ÏÂÃæµÄ´úÂ룺
sychronized¹Ø¼ü×ÖÖ»ºÍÒ»¸ö¶ÔÏóʵÀý°ó¶¨
class Test
{
public synchronized void method()
{
}
}
public class Sync implements Runnable
{
private Test test;
public void run()
{
test.method();
}
public Sync(Test test)
{
this.test = test;
}
public static void main(String[] args) throws Exception
{
Test test1 = new Test();
Test test2 = new Test();
Sync sync1 = new Sync(test1);
Sync sync2 = new Sync(test2);
new Thread(sync1).start();
new Thread(sync2).start();
}
}
ÔÚTestÀàÖеÄmethod·½·¨ÊÇͬ²½µÄ¡£µ«ÉÏÃæµÄ´úÂ뽨Á¢ÁËÁ½¸öTestÀàµÄʵÀý£¬Òò´Ë£¬test1ºÍtest2µÄmethod·½·¨ÊÇ·Ö±ðÖ´Ðеġ£ÒªÏëÈÃmethodͬ²½£¬±ØÐëÔÚ½¨Á¢SyncÀàµÄʵÀýʱÏòËüµÄ¹¹Ôì·½·¨Öд«Èëͬһ¸öTestÀàµÄʵÀý£¬ÈçÏÂÃæµÄ´úÂëËùʾ£º
Sync sync1 = new Sync(test1);
²»½ö¿ÉÒÔʹÓÃsynchronizedÀ´Í¬²½·Ç¾²Ì¬·½·¨£¬Ò²¿ÉÒÔʹÓÃsynchronizedÀ´Í¬²½¾²Ì¬·½·¨¡£Èç¿ÉÒÔ°´ÈçÏ·½Ê½À´¶¨Òåmethod·½·¨£º
class Test
{
public static synchronized void method() { }
}
½¨Á¢TestÀàµÄ¶ÔÏóʵÀýÈçÏ£º
Test test = new Test();
¶ÔÓÚ¾²Ì¬·½·¨À´Ëµ£¬Ö»Òª¼ÓÉÏÁËsynchronized¹Ø¼ü×Ö£¬Õâ¸ö·½·¨¾ÍÊÇͬ²½µÄ£¬ÎÞÂÛÊÇʹÓÃtest.method()£¬»¹ÊÇʹÓÃTest.method()À´µ÷ÓÃmethod·½·¨£¬method¶¼ÊÇͬ²
Ïà¹ØÎĵµ£º
µ±ÖØÔØequals·½·¨Ê±,×ñѹßÀý.
equals²»ÊÇÿ¸öÀ඼±ØÐëÖØÔØ,µ±ÒÔϼ¸¸öÌõ¼þÂú×ã,¿ÉÒÔ²»ÖØÔØequals.
1. ÀàµÄʵÀýÖ»ÓÐͬһ¸ö²Å±»ÅÐΪÏàµÈ. ÈçThreadÀà.
2. ²»ÓùØÐÄÁ½¸ö¶ÔÏóÊÇ·ñÂß¼ÏàµÈµÄʱºò,»òÊÇ˵±È½Ï¶ÔÏóûÓÐÒâÒå.
3.¸¸ÀàÒѾÖØÔØÁËequals,¶øÇÒ¸¸ÀàµÄequalsÒ²ÊÊÓÃÓÚ×ÓÀà,×ÓÀà¾Í²»ÓÃÖØÔØequals.
4.ÕâÊÇÒ»¸ö˽ÓÐÀà»òÊ ......
Ò»¡¢Servlet¹ýÂËÆ÷µÄ¸ÅÄ
*******************************************************
Servlet¹ýÂËÆ÷ÊÇÔÚJava Servlet¹æ·¶2.3Öж¨ÒåµÄ£¬ËüÄܹ»¶ÔServletÈÝÆ÷µÄÇëÇóºÍÏìÓ¦¶ÔÏó½øÐмì²éºÍÐ޸ġ£¡¡¡¡¡¡
Servlet¹ýÂËÆ÷±¾Éí²¢²»²úÉúÇëÇóºÍÏìÓ¦¶ÔÏó£¬ËüÖ»ÄÜÌṩ¹ýÂË×÷Óá£Servlet¹ýÆÚÄܹ»ÔÚServlet±»µ÷ÓÃ֮ǰ¼ì²éRequest¶ÔÏó£ ......
Ò»¡¢cookie»úÖƺÍsession»úÖƵÄÇø±ð
*****************************************************************
¾ßÌåÀ´Ëµcookie»úÖƲÉÓõÄÊÇÔÚ¿Í»§¶Ë±£³Ö״̬µÄ·½°¸£¬¶øsession»úÖƲÉÓõÄÊÇÔÚ·þÎñÆ÷¶Ë±£³Ö״̬µÄ·½°¸¡£
ͬʱÎÒÃÇÒ²¿´µ½£¬ÓÉÓڲŷþÎñÆ÷¶Ë±£³Ö״̬µÄ·½°¸ÔÚ¿Í»§¶ËÒ²ÐèÒª±£´æÒ»¸ö±êʶ£¬ËùÒÔsession
»úÖÆ¿ÉÄÜÐèÒª½è ......
Java»ù´¡Ð¡½á(ÊýÖµÀàÐÍת»»¹æÔò)
Ò»¡¡ÊýÖµÀàÐÍת»»¹æÔò
ÊýÖµÐÍÊý¾Ý½øÐÐÔËËãʱ£¬Èç¹û²Ù×÷ÊýµÄÀàÐͲ»Í¬»ò²Ù×÷ÊýµÄÀàÐ;ùµÍÓÚintÐÍ£¬Ôò
»á½øÐÐ×Ô¶¯ÀàÐÍת»»´¦Àí£¬¾ßÌå¹æÔòÈçÏ£º
1)Èç¹ûÁ½¸ö²Ù×÷ÊýÖÐÓÐÒ»¸öÊÇdoubleÐÍ£¬ÔòϵͳÏȽ«ÁíÒ»¸ö²Ù×÷ÊýµÄֵת»»Îªdouble
ÐÍ£¬È»ºóÔÙ½øÐÐÔËË㣬·ñÔò
2)Èç¹ûÁ½¸ö²Ù×÷ÊýÖÐÓÐÒ»¸öÊÇfloat ......
Java³£¼ûÎÊÌ⼯½õ:
ÎÊ:ÈçºÎÉèÖÃJava 2(JDK1.2)µÄ»·¾³±äÁ¿?
´ð:Java 2°²×°ºó,ÐèÒªÉèÖÃPATHºÍJAVA_HOME»·¾³±äÁ¿.ÓëJDK1.1²»Í¬µÄÊÇ:ÉèÖúÃJAVA_HOME»·¾³±äÁ¿ºó,JVM½«×Ô¶¯ËÑË÷ϵͳÀà¿âÒÔ¼°Óû§µÄµ±Ç°Â·¾¶.
Java 2»·¾³±äÁ¿µÄÉèÖÃÈçÏÂÀýËùʾ:
Solarisƽ̨: setenv JAVA_HOME Java2µÄ°²×°Â·¾¶
setenv PATH /bin:/p/2002-11-14 ......