奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

java語言

Java實(shí)現(xiàn)在不同線程中運(yùn)行的代碼實(shí)例詳解

時(shí)間:2025-05-14 03:57:20 java語言 我要投稿
  • 相關(guān)推薦

Java實(shí)現(xiàn)在不同線程中運(yùn)行的代碼實(shí)例詳解

  本文實(shí)例講述了Java實(shí)現(xiàn)在不同線程中運(yùn)行的代碼。下面是由百分網(wǎng)小編為大家整理的Java實(shí)現(xiàn)在不同線程中運(yùn)行的代碼實(shí)例詳解,喜歡的可以收藏一下!了解更多詳情資訊,請(qǐng)關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)!

  start()方法開始為一個(gè)線程分配CPU時(shí)間,這導(dǎo)致對(duì)run()方法的調(diào)用。

  代碼1

  package Threads;

  /**

  * Created by Frank

  */

  public class ThreadsDemo1 extends Thread {private String msg;

  private int count;

  public ThreadsDemo1(final String msg, int n) {this.msg = msg;

  count = n;

  setName(msg + " runner Thread");

  }

  public void run() {

  while (count-- > 0) {

  System.out.println(msg);

  try {

  Thread.sleep(100);

  } catch (InterruptedException e) {

  return;

  }

  }

  System.out.println(msg + " all done.");

  }

  public static void main(String[] args) {

  new ThreadsDemo1("Hello from X", 10).start();new ThreadsDemo1("Hello from Y", 15).start();}

  }

  代碼2:

  package Threads;

  /**

  * Created by Frank

  */

  public class ThreadsDemo2 implements Runnable {private String msg;

  private Thread t;

  private int count;

  public static void main(String[] args) {

  new ThreadsDemo2("Hello from X", 10);

  new ThreadsDemo2("Hello from Y", 15);

  }

  public ThreadsDemo2(String m, int n) {

  this.msg = m;

  count = n;

  t = new Thread(this);

  t.setName(msg + "runner Thread");

  t.start();

  }

  public void run() {

  while (count-- > 0) {

  System.out.println(msg);

  try {

  Thread.sleep(100);

  } catch (InterruptedException e) {

  return;

  }

  }

  System.out.println(msg + " all done.");

  }

  }

  代碼3:

  package Threads;

  /**

  * Created by Frank

  */

  public class ThreadsDemo3 {

  private int count;

  public static void main(String[] args) {

  new ThreadsDemo3("Hello from X", 10);

  new ThreadsDemo3("Hello from Y", 15);

  }

  public ThreadsDemo3(final String msg, int n) {this.count = n;

  Thread t = new Thread(new Runnable() {

  public void run() {

  while (count-- > 0) {

  System.out.println(msg);

  try {

  Thread.sleep(100);

  } catch (InterruptedException e) {

  return;

  }

  }

  System.out.println(msg + " all done.");

  }

  });

  t.setName(msg + " runner Thread");

  t.start();

  }

  }

  eclipse運(yùn)行結(jié)果如下:

【Java實(shí)現(xiàn)在不同線程中運(yùn)行的代碼實(shí)例詳解】相關(guān)文章:

java中通用的線程池實(shí)例代碼08-27

Java裝箱與拆箱詳解(附實(shí)例代碼)02-11

如何創(chuàng)建并運(yùn)行Java線程01-11

java多線程-線程通信實(shí)例詳細(xì)解讀07-07

java從代碼到運(yùn)行的過程07-26

Java基礎(chǔ)從代碼到運(yùn)行06-17

Java優(yōu)先級(jí)線程代碼示例08-09

詳解java線程的生命周期04-03

java Runnable接口創(chuàng)建線程詳解02-15

主站蜘蛛池模板: 张掖市| 怀仁县| 柳江县| 尉氏县| 阳西县| 九台市| 边坝县| 南涧| 高平市| 桦甸市| 桐乡市| 浦江县| 葫芦岛市| 霍邱县| 临海市| 南川市| 华坪县| 临泉县| 棋牌| 平南县| 双辽市| 施甸县| 长岭县| 衢州市| 舞钢市| 蒙自县| 高清| 新民市| 博湖县| 金乡县| 子洲县| 大兴区| 天峻县| 哈尔滨市| 大冶市| 朝阳县| 易门县| 绵竹市| 监利县| 南安市| 虎林市|