Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Java¶àÏ̱߳à³ÌÖеÄSynchronized

Synchronized£¬¹ËÃû˼Ò壬´ú±í¶à¸öÏß³ÌÖ®¼äµÄͬ²½¡£ÄÇô£¬ÔÚjava±à³ÌÖÐÈçºÎʹÓÃËüÄØ£¿ ÎÒÃǼÙÉèÕâÑùÒ»¸öÇé¿ö£º¶ÔÓÚͬһ¸ö±äÁ¿synDemo£¬ÎÒÃÇ·Ö±ðÔÚ2¸ö²»Í¬µÄÏß³ÌÖе÷ÓÃsynDemo.synMethord1()ÓësynDemo.synMethord2()¡£ package com.cnblogs.gpcuster;
/**
*
* @author Aaron.Guo
*
*/
public class Tester {
public static void main(String[] args) {
final SynDemo synDemo = new SynDemo();
Thread thread1 = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
synDemo.synMethord1();
}
};
Thread thread2 = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
synDemo.synMethord2();
}
};
thread1.start();
thread2.start();
while (true) {
try {
Thread.sleep(1000);
System.out.println("main");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
ÎÒÃǵÄSynDemoÊÇÕâÑù¶¨ÒåµÄ£º
package com.cnblogs.gpcuster;
/**
*
* @author Aaron.Guo
*
*/
public class SynDemo{

public void synMethord1() {
while(true) {
try {
Thread.sleep(1000);
System.out.println("synMethord1");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public void synMethord2() {
while(true) {
try {
Thread.sleep(1000);
System.out.println("synMethord2");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
ÎÒÃǵÄSynDemo¶ÔÏóûÓÐÈκÎÌØÊâµÄ¶¨Ò壬ËùÒÔÔËÐÐÆðÀ´ÒÔºóµÄÇé¿öÈçÏ£º
synMethord2

synMethord1

main

synMethord2

synMethord1

main

synMethord2

synMethord1
½ÓÏÂÀ´£¬ÎÒÃǸøsynMethord1Ìí¼ÓÉÏsynchronizedÉùÃ÷£¬ÔËÐÐÇé¿ö»¹ÊÇÓëÉÏ´ÎÒ»Ñù£¬ÒòΪÎÒÃÇÖ»ÓÐÒ»¸öÏß³ÌÔÚµ÷ÓÃsynMethord1µÄ·½·¨¡£
ÎÒÃǸøsynMethord2Ò²Ìí¼ÓÉÏsynchronizedÉùÃ÷£¬SynDemo¶ÔÏóµÄ´úÂë


Ïà¹ØÎĵµ£º

Javaʵѵ

 ÎÒÃÇÿ¸öѧÆÚÄ©¶¼»á½øÐн«½üÒ»¸öÔµÄʵѵ£¬Õâ´ÎJavaʵѵҲ¼´½«½áÊø£¬ÎÒÑ¡µÄ¿ÎÌâÊÇ“¸öÈËÍøÉÏÒøÐÐϵͳ”£¬ÔËÓÃÁËStruts£¬HibernateºÍSpring¿ò¼Ü£¬Í¨¹ýmvcÉè¼Æģʽ¡£»ù±¾ËùÓеŦÄܶ¼ÊµÏÖÁË£¬ÔÚʵѵÖÐÕæµÄѧµ½Á˺ܶà֪ʶ£¬Ö®¼äÒ²Óöµ½Á˺ܶàÎÊÌ⣬µ«¶¼Ò»Ò»µÃµ½½â¾ö¡£ÎÒ½øÒ»²½Á˽âÁËStrutsµÄÔËÐÐÔ­Àí£¬ÂíÉÏÃæÁÙ ......

Java Scanner NoSuchElementException

½ñÌìͬѧÎÊÎÒÒ»¸öJavaÎÊÌ⣬´úÂë½á¹¹ÈçÏ£º
Scanner scan = new Scanner(System.in);
scan.next();
scan.close();
scan = new Scanner(System.in);
scan.next(); 
µ±³ÌÐòÔËÐе½µÚÎåÐÐÊÇ»áÅ׳öjava.util.NoSuchElementException
          at&nb ......

java±àÂëת»»

³£¼ûµÄJAVA³ÌÐò°üÀ¨ÒÔÏÂÀà±ð£º
*Ö±½ÓÔÚconsoleÉÏÔËÐеÄÀà(°üÀ¨¿ÉÊÓ»¯½çÃæµÄÀà)
*JSP´úÂëÀࣨע£ºJSPÊÇServletsÀàµÄ±äÐÍ£©
*ServeletsÀà
*EJBÀà
*ÆäËü²»¿ÉÒÔÖ±½ÓÔËÐеÄÖ§³ÖÀà
 
ÕâЩÀàÎļþÖУ¬¶¼ÓпÉÄܺ¬ÓÐÖÐÎÄ×Ö·û´®£¬²¢ÇÒ³£ÓÃÇ°ÈýÀàJAVA³ÌÐòºÍÓû§Ö±½Ó½»»¥£¬ÓÃÓÚÊä³öºÍÊäÈë×Ö·û£¬È磺ÔÚJSPºÍServletÖеõ½¿Í»§ ......

»ù´¡ JAVA³ÌÐò


1.±à³Ì½ç×îÖøÃûµÄÒ»¾ä»°“Hello world!”,ÈκÎÒ»¸ö³ÌÐòÔ±Æð²½Ê±±ØÓöµÄÓï¾ä
public class HelloWorld {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("Hello World!");
......

java¶þ·Ö²éÕÒ

¶þ·Ö²éÕÒ£º
   ¶þ·Ö²éÕÒ±ÈÏßÐÔ²éÕÒÊý¶ÈÒªºÃºÜ¶à£¬ÓÈÆäÊǶԴóÊý×éÀ´Ëµ¸üΪÏÔÖø£¬¾ÍÏñÊDzÂ×ÖÓÎÏ·Ò»Ñù
²Â×ÖÓÎÏ·£º
   ¶þ·Ö²éÕҵķ½·¨ºÍÎÒÃÇСʱºòÍæµÄ²Â×ÖÓÎÏ·ÊÇÒ»ÑùµÄ¡£ÔÚÕâ¸öÓÎÏ·ÀïÃ棬ÓÐÒ»¸öСÅóÓÑ»áÈÃÄã²ÂËýÕýÔÚÏëµÄÒ»¸ö1ÖÁ100Ö®¼äµÄÊý£¬
Äã²ÂÁËÒ»¸öÊýÒÔºó£¬Ëý»á¸æËßÄãÈýÖÖÑ¡ÔñÖеÄÒ»¸ö£ºÄã² ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ