熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java高級技術 >> 正文

Java中多線程之間可以通過接口來實現信息共享

2022-06-13   來源: Java高級技術 

  提供一段示例代碼

  import javautilArrayList;

  /**

  *

  * @author WeiLiu

  */

  public class Main {

  public interface var{

  public static ArrayList all=new ArrayList();

  }

  static class Thread extends Thread implements var{

  private int id;

  public Thread(int tempid){

  thisid = tempid;

  }

  @Override

  public void run() {

  int count=;

  while(count<){

  alladd(thisid);

  count++;

  Systemoutprintln(allsize());

  }

  }

  }

  public static void main(String[] args) {

  Thread temp = new Thread();

  Thread temp = new Thread();

  tempstart();

  tempstart();

  }

  }


From:http://tw.wingwit.com/Article/program/Java/gj/201311/27376.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.