Java 2 protocol · ¢ ± à ³ Ì Ö®Please refer to your website for more information» ¥ ³ â ± Ç

Source: Internet
Author: User

Java 2 protocol · ± à Ì öï ß Ì» ¥ â ± Ç

public class Client {public static void main(String[] args) { MyShow show=new MyShow();//ÕâÊÇÔÚ¾²Ì¬·½·¨ÖУ¨ÄÚ²¿ÀàÓпÉÒÔ·ÃÎÊÍⲿÀàµÄÊôÐÔµÄÐÔÖÊ£µ«ÊÇÀï×ö²»µ½£¬ËùÒÔ´íÎó¡£new Thread(new Runnable() {@Overridepublic void run() {show.showInfo("test");}}).start();new Thread(new Runnable() {@Overridepublic void run() {}}).start();}class MyShow{public void showInfo(String name){for(int i=0;i
 
  

  

  

  

  


´úÂëÐÞ¸ÄÈçÏ£º

public class Client {public static void main(String[] args) { final MyShow show=new MyShow();new Thread(new Runnable() {@Overridepublic void run() {while(true){show.showInfo("code");try {Thread.sleep(500);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}).start();new Thread(new Runnable() {@Overridepublic void run() {while(true){show.showInfo("monkey");try {Thread.sleep(560);} catch (Exception e) {// TODO: handle exception}}}}).start();}
//¾²Ì¬ÄÚ²¿ÀàµÈͬÓÚÍⲿÀàstatic class MyShow{public void showInfo(String name){for(int i=0;i
   
    ×¢Ò⣺ÄÚ²¿Àà¿ÉÒÔ·ÃÎÊÍⲿÀàµÄ³ÉÔ±±äÁ¿£¬ËùÒÔÒªÏÈÓÐÍⲿÀ࣬ÔÚ¾²Ì¬·½·¨ÖÐûÓС£ÄÚ²¿ÀàÒª·ÃÎÊÍⲿÀàµÄ¾Ö²¿±äÁ¿£¬¾Ö²¿±äÁ¿Òª¼Ófinal¡£¾²Ì¬ÄÚ²¿ÀàÏ൱ÓÚÍⲿÀ࣬¿ÉÒÔÓо²Ì¬·½·¨¡£¾²Ì¬·½·¨ºÍ×Ö½ÚÂë¶ÔÏó¹ØÁª£¨×Ö½ÚÂëÒѾ¼ÓÔØÔÚÄÚ´æÖУ
    

ÔËÐнá¹û£º


³öÏÖ´íÎ󣡣¡£¡½ÓÏÂÀ´Òª½â¾öḬ̈߳²È«µÄÎÊÌâ¡£<†·Ÿ"http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGJyPgo8L3A+CjxwPtTawdm958r9vt278tXfysfS18vpyv2+3bzTyc+21M/zy/i52Lz819bI58/Co7o8L3A+CjxwPjxwcmUgY2xhc3M9"brush:java;">static class MyShow{public void showInfo(String name){synchronized (this) {for(int i=0;i
thisÊǸöÔÏóÄÚ²¿£¬ÆäËûµØ·½µ÷ÓþÍÊÇnew³öÀ´µÄ¶ÔÏó¡£

»òÕßÒ»¸öͬ²½·½·¨Ò²¿ÉÒÔ½â¾ö£º

static class MyShow{//µ±Ç°¶ÔÏóËøpublic synchronized void showInfo(String name){for(int i=0;i
     
      
±¾ÖÊ£¬Èç¹ûÒª±£Ö¤Ï̵߳ݲȫ£¬¾ÍÒª×öµ½ÊǶÔͬһ¸ö¶ÔÏó¼ÓËø¡£Ã¿¸öÏ̷߳ÃÎʸöÔÏó¾Í²»»á³öÏÖÏ̲߳»Í¬²½µÄÎÊÌâÁË¡£


public class Client {public static void main(String[] args) { final MyShow show=new MyShow();new Thread(new Runnable() {@Overridepublic void run() {while(true){show.showInfo("code");show.showInfo2("code");MyShow.showInfo3("code");try {Thread.sleep(500);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}).start();new Thread(new Runnable() {@Overridepublic void run() {while(true){show.showInfo("monkey");show.showInfo2("monkey");MyShow.showInfo3("monkey");try {Thread.sleep(560);} catch (Exception e) {// TODO: handle exception}}}}).start();}static class MyShow{//µ±Ç°¶ÔÏóËøpublic synchronized void showInfo(String name){synchronized(this){//³öÎÊÌâµÄµØ·½¸Ä³ÉMyShow.class¼´¿É½â¾ö¡£for(int i=0;i
       
        


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.