亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 線程代碼.txt

?? 適合初學者練習 包括awt小程序、list和map群體等100多個java程序
?? TXT
字號:
線程代碼 List.1 Thread.txt 
線程代碼 List.2 ThreadDemo/ThreadDemo.java 
線程代碼 List.3 Runnable.txt 
線程代碼 List.4 Primes/Primes.java 
線程代碼 List.5 SafetyClass/SafetyClass.java 
線程代碼 List.6 LockDemo/Queue.java 
線程代碼 List.7 LockDemo/Job.java 
線程代碼 List.8 LockDemo/Server.java 
線程代碼 List.9 LockDemo/Client.java 
線程代碼 List.10 LockDemo/LockDemo.java 

--------------------------------------------------------------------------------

線程代碼 List.1 Thread.txt 
Return to top 
001: // Public fields
002: public final static int MIN_PRIORITY = 1;
003: public final static int NORM_PRIORITY = 5;
004: public final static int MAX_PRIORITY = 10;
005: 
006: // Constructors
007: public Thread();
008: public Thread(Runnable target);
009: public Thread(ThreadGroup group, Runnable target);
010: public Thread(String name);
011: public Thread(ThreadGroup group, String name);
012: public Thread(Runnable target, String name);
013: public Thread(ThreadGroup group, Runnable target, String name);
014: 
015: // Public methods
016: public static native Thread currentThread();
017: public static native void yield();
018: public static native void sleep(long millis);
019: public static void sleep(long millis, int nanos);
020: private void init(ThreadGroup g, Runnable target, String name);
021: public synchronized native void start();
022: public void run();
023: private void exit();
024: public void interrupt();
025: public static boolean interrupted();
026: public boolean isInterrupted();
027: public final native boolean isAlive();
028: public final void setPriority(int newPriority);
029: public final int getPriority();
030: public final void setName(String name);
031: public final String getName();
032: public final ThreadGroup getThreadGroup();
033: public static int activeCount();
034: public static int enumerate(Thread tarray[]);
035: public native int countStackFrames();
036: public final synchronized void join(long millis);
037: public final synchronized void join(long millis, int nanos);
038: public final void join();
039: public static void dumpStack();  // debugging only
040: public final void setDaemon(boolean on);
041: public final boolean isDaemon();
042: public final void checkAccess();
043: public String toString();
044: public ClassLoader getContextClassLoader();
045: public void setContextClassLoader(ClassLoader cl);
046: 
047: // Deprecated methods -- DO NOT CALL!
048: public final void stop();
049: public final synchronized void stop(Throwable obj);
050: public final void suspend();
051: public final void resume();

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.2 ThreadDemo/ThreadDemo.java 
Return to top 
001: import java.io.IOException;
002: 
003: // Extend Thread class and provide a run() method
004: class Background extends Thread {
005: 
006:  boolean finished;  // True when thread should die
007: 
008:  // Constructor
009:  Background(String name) {
010:   super(name);
011:   finished = false;  // Initialize run-flag
012:  }
013: 
014:  // Called by start() to run the thread
015:  public void run() {
016:   try {
017:    while (!finished) {   // Loop "forever"
018:     sleep(2000);
019:     System.out.println("/nHurry up!");
020:     sleep(1000);
021:     System.out.println("/nWhat's taking you so long?");
022:     sleep(1500);
023:     System.out.println("/nC'mon, press that Enter key!");
024:    }
025:   } catch (InterruptedException e) {
026:    return;  // End the thread
027:   }
028:  }
029: 
030:  // Halt the thread
031:  public void halt() {
032:   finished = true;  // Cause while loop in run() to end
033:   System.out.println("Stopping thread " + getName() + "/n");
034:  }
035: }
036: 
037: // Main program class demonstrates background processing
038: class ThreadDemo {
039:  public static void main(String args[]) {
040: 
041: // Create the background thread
042:   Background background = 
043:    new Background("Background process");
044:   System.out.println(
045:     "Starting thread. Press Enter to stop.");
046: 
047: // Start running the background thread
048:   background.start();
049: 
050: // Simulate foreground process: wait for Enter key
051:   try {
052:    while ((char)System.in.read() != '/n') ;
053:   } catch (IOException e) {
054:    System.out.println(e.getMessage());
055:   }
056: 
057: // Stop the background thread
058:   background.halt();
059:  }
060: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.3 Runnable.txt 
Return to top 
001: // The Runnable interface
002: public interface Runnable {
003:  public abstract void run();
004: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.4 Primes/Primes.java 
Return to top 
001: import java.io.IOException;
002: 
003: class Background implements Runnable {
004:  
005:  boolean finished = false;  // True to end run()
006:  int num = 3;               // Prime number candidates
007:  int delay;                 // Time between each output
008: 
009:  // Constructor
010:  Background(int delay) {
011:   this.delay = delay;
012:  }
013: 
014:  // Return true if num is a prime number
015:  public boolean isPrime(int n) {
016:   for (int i = 2; i < n; i++)
017:    if ((n % i) == 0)
018:     return false;
019:   return true;
020:  }
021: 
022:  // Search for prime numbers in the background
023:  public void run() {
024:   try {
025:    while (!finished) {
026:     if (isPrime(num))
027:      System.out.println(num);
028:     num++;
029:     Thread.sleep(delay);
030:    } // while
031:   } catch (InterruptedException e) {
032:    return;
033:   }
034:  }
035: 
036:  // Set flag to stop run()
037:  public void halt() {
038:   finished = true;
039:  }
040: 
041: }
042: 
043: // Compute prime numbers in the background
044: class Primes {
045: 
046:  static char getChar() {
047:   char ch = '/0';
048:   try {
049:    ch = (char)System.in.read();
050:   } catch (IOException e) {
051:    System.out.println(e.getMessage());
052:   }
053:   return ch;
054:  }
055: 
056:  static void waitForKey(char key) {
057:   while (getChar() != key) /* wait */ ;
058:  }
059: 
060:  public static void main(String args[]) throws Exception {
061:   System.out.println("Press Enter to begin and again to quit");
062:   waitForKey('/n');
063:   // Construct and start thread
064:   Background background = new Background(50);
065:   Thread T = new Thread(background);
066:   T.setPriority(4);
067:   T.start();
068:   // Wait for Enter key while thread runs
069:   waitForKey('/n');
070:   background.halt();  // Stop the thread
071:  }
072: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.5 SafetyClass/SafetyClass.java 
Return to top 
001: // Illustration only: not a complete program
002: public class SafetyClass {
003: 
004:  private int counter;  // Private data in class
005: 
006: // Thread-safe method to write data
007:  public synchronized void setCounter(int n) {
008:   counter = n;         // Assign new value to counter
009:  }
010: 
011: // Thread-safe method to read data
012:  public synchronized int getCounter() {
013:   return counter;      // Return counter's current value
014:  }
015: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.6 LockDemo/Queue.java 
Return to top 
001: import java.util.LinkedList;
002: 
003: public class Queue {
004: 
005:  private LinkedList q = new LinkedList();
006: 
007:  public synchronized void add(Object o) {
008:   q.add(o);
009:  }
010: 
011:  public synchronized Object get() 
012:   throws InterruptedException {
013:   while (q.isEmpty())
014:    wait();
015:   return q.removeFirst();
016:  }
017: 
018:  public synchronized boolean isEmpty() {
019:   return q.isEmpty();
020:  }
021: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.7 LockDemo/Job.java 
Return to top 
001: public class Job implements Runnable {
002: 
003:  private String name;    // Name of this job
004:  private int delay;      // How long it takes to do this job
005:  private boolean ready;  // True when job is ready to be done
006: 
007: // Constructor
008:  Job(String name, int delay) {
009:   this.name = name;
010:   this.delay = delay;
011:   ready = false;
012:   new Thread(this).start();  // Job runs itself in a thread!
013:  }
014: 
015: // Run method called by thread scheduler
016:  public void run() {
017:   try {
018:    doWhenReady();  // Do the job when it is ready
019:   } catch (InterruptedException e) {
020:    return;
021:   }
022:  }
023: 
024: // Performs the job's actual work
025: // Because this calls wait(), code cannot be in run()
026: // and it must be synchronized on this object
027:  private synchronized void doWhenReady()
028:   throws InterruptedException {
029:   while (!ready)
030:    wait();        // Wait indefinitely until ready
031: // Simulate the job by displaying messages and sleeping
032: // for the amount of time this job takes
033:   System.out.println("/nStarting " + name);
034:   System.out.println("Time = " + delay / 1000 + " second(s)");
035:   Thread.currentThread().sleep(delay);  // Simulate job runtime
036:   System.out.println("/nFinishing " + name);
037:   System.out.println("Ending thread " + toString());
038:  }
039: 
040: // Set the thread state flag to true 
041: // and notify all threads of the change
042:  public synchronized void doJob() {
043:   ready = true;
044:   notifyAll();
045:  }
046: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.8 LockDemo/Server.java 
Return to top 
001: import Queue;
002: import Job;
003: 
004: class Server implements Runnable {
005: 
006:  Queue q = new Queue();  // Construct our Queue object 
007: 
008:  public void run() {
009:   try {
010:    doWhenReady();  // Do the server's activities
011:   } catch (InterruptedException e) {
012:    return;
013:   }
014:  }
015: 
016: // Perform server activities until shutdown
017:  private synchronized void doWhenReady()
018:   throws InterruptedException {
019:   for (;;) {              // Do "forever" loop
020:    while (q.isEmpty())    // Wait until there is a job in 
021:     wait();               //  the queue
022:    Job j = (Job)q.get();  // Get the job
023:    j.doJob();             // Do the job
024:   } // for
025:  }
026: 
027: // Add a new job to the server's queue
028: // This returns immediately; the job is not performed
029: // until the server thread detects the queue is no longer
030: // empty. 
031:  public synchronized void add(Job j) {
032:   q.add(j);
033:   notifyAll();
034:  }
035: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.9 LockDemo/Client.java 
Return to top 
001: import java.util.Random;
002: import Job;
003: import Server;
004: 
005: class Client implements Runnable {
006: 
007:  Random rand = new Random();
008:  boolean finished = false;
009:  int jobcount = 0;
010: 
011: // Utility method creates a new numbered job with
012: // a random time delay to simulate how long the job takes
013:  private Job getAJob() {
014:   String name = "Job #" + ++jobcount;
015:   int delay = 1000 + rand.nextInt(9000);  // 1 .. 10 seconds
016:   Job j = new Job(name, delay);
017:   return j;
018:  }
019: 
020:  public void run() {
021: 
022: // Create the server daemon thread
023:   Server server = new Server();
024:   Thread T = new Thread(server);
025:   T.setDaemon(true);  // Server is a daemon!
026:   T.start();          // Start the server thread running
027: 
028: // Main run() actions
029:   try {
030:    while (!finished) {
031: 
032:    // Create a job and pass it to the server
033:     Job j = getAJob();  // Create simulated job object
034:     server.add(j);      // Returns immediately
035: 
036:    // Simulate user activity by sleeping a random time
037:     int time = 1000 + rand.nextInt(5000);
038:     System.out.println("Sleeping for " + 
039:      time / 1000 + " second(s)");
040:     Thread.currentThread().sleep(time);
041: 
042:    }
043:   } catch (InterruptedException e) {
044:    return;
045:   }
046:  }
047: 
048: // Halt the client
049: // However, all job threads finish to completion!
050:  public synchronized void halt() {
051:   finished = true;
052:   notifyAll();
053:  }
054: }

Return to top 
--------------------------------------------------------------------------------

線程代碼 List.10 LockDemo/LockDemo.java 
Return to top 
001: import java.io.IOException;
002: import java.util.*;
003: import Client;
004:   
005: class LockDemo {
006: 
007: // Get a character from keyboard
008:  static char getChar() {
009:   char ch = '/0';
010:   try {
011:    ch = (char)System.in.read();
012:   } catch (IOException e) {
013:    System.out.println(e.getMessage());
014:   }
015:   return ch;
016:  }
017: 
018: // Wait for user to press a specified key
019:  static void waitForKey(char key) {
020:   while (getChar() != key) /* wait */ ;
021:  }
022: 
023:  public static void main(String args[]) {
024: 
025: // Construct and start the client (job creator) thread
026:   Client client = new Client();
027:   new Thread(client).start();
028: 
029: // Wait for Enter key so threads can run
030:   System.out.println("/n<<< Press Enter to end program >>>/n");
031:   waitForKey('/n');  // All threads run while waiting
032: 
033: // Halt the client thread; sever daemon also ends
034: // However, any remaining job threads finish to completion!
035:   client.halt();
036:  }
037: }

Return to top 
? 2003 by ChinaITLab.com All rights reserved. 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线欧美日韩国产| 日韩美女啊v在线免费观看| 久久精品亚洲一区二区三区浴池| 国产精品久久久久久久久果冻传媒| 亚洲超碰97人人做人人爱| 国产乱人伦偷精品视频免下载 | 中文字幕一区在线观看视频| 亚洲1区2区3区4区| k8久久久一区二区三区| 精品国产一区二区三区久久久蜜月 | 在线精品视频免费观看| 久久久久久久国产精品影院| 亚洲成av人片在线观看无码| 成人av小说网| 精品美女被调教视频大全网站| 亚洲午夜私人影院| 色综合久久中文字幕| 国产精品网站在线| 国产做a爰片久久毛片| 日韩欧美中文字幕精品| 午夜精品久久久久久久99樱桃| 91看片淫黄大片一级| 国产精品国产三级国产普通话蜜臀| 九色porny丨国产精品| 欧美一级搡bbbb搡bbbb| 亚洲第一久久影院| 欧洲精品中文字幕| 亚洲精品高清在线| 一本到不卡免费一区二区| 欧美国产精品一区二区三区| 国产精品一区二区果冻传媒| 久久久久久久久久久电影| 精品一区二区三区在线播放视频| 日韩欧美激情一区| 经典三级一区二区| 久久久777精品电影网影网| 在线中文字幕不卡| 一区二区三区在线观看国产| 97精品视频在线观看自产线路二| 国产精品女主播av| 91丨九色丨蝌蚪丨老版| 亚洲欧美日韩在线| 欧美视频精品在线| 日韩影院精彩在线| 日韩一区二区精品在线观看| 久久精品国产99国产精品| 久久嫩草精品久久久精品一| 风流少妇一区二区| 亚洲欧美色图小说| 欧美日韩国产一区二区三区地区| 日韩中文字幕一区二区三区| 日韩欧美国产精品| 国产不卡一区视频| 亚洲伦理在线免费看| 欧美乱妇23p| 久久er精品视频| 国产日韩欧美精品在线| 99久久久无码国产精品| 亚洲成人在线免费| 久久视频一区二区| 91毛片在线观看| 日韩黄色小视频| 国产亚洲一区字幕| 欧美亚洲精品一区| 久久99精品视频| 亚洲视频在线观看三级| 欧美一区二区三区免费在线看| 国产揄拍国内精品对白| 亚洲色图在线视频| 日韩欧美二区三区| 91在线国内视频| 美女脱光内衣内裤视频久久网站 | 久久久午夜电影| 91麻豆高清视频| 久久精品噜噜噜成人av农村| 国产精品嫩草99a| 日韩一区二区三区在线| 日韩免费福利电影在线观看| 99久久精品免费| 免费成人性网站| 亚洲天堂成人在线观看| 欧美大肚乱孕交hd孕妇| 在线中文字幕不卡| 国产aⅴ精品一区二区三区色成熟| 亚洲国产综合视频在线观看| 国产日韩欧美电影| 日韩欧美一区中文| 在线亚洲免费视频| 成人免费高清视频| 毛片av一区二区| 亚洲国产日韩一区二区| 国产精品久久久久久一区二区三区 | 欧美精品少妇一区二区三区| av不卡免费在线观看| 久久97超碰国产精品超碰| 一区二区三区四区视频精品免费 | 一区二区三区国产精华| 国产三级三级三级精品8ⅰ区| 欧美巨大另类极品videosbest| 91在线免费看| 懂色av噜噜一区二区三区av| 精品一区二区免费看| 日韩av电影免费观看高清完整版 | 欧美日韩一区 二区 三区 久久精品| 国产成a人无v码亚洲福利| 精东粉嫩av免费一区二区三区| 99国产麻豆精品| 国产成人在线观看免费网站| 久久狠狠亚洲综合| 免费成人深夜小野草| 午夜精品在线视频一区| 亚洲一区二区三区四区在线| 亚洲欧美日韩人成在线播放| 国产精品福利影院| 国产精品青草久久| 国产日韩成人精品| 久久精品一区二区三区不卡牛牛| 精品欧美久久久| 欧美va天堂va视频va在线| 日韩欧美中文一区| 精品国产三级a在线观看| 欧美不卡视频一区| 精品区一区二区| 国产三级久久久| 中文字幕欧美三区| 国产精品超碰97尤物18| 亚洲精品一二三四区| 亚洲国产综合91精品麻豆| 亚洲r级在线视频| 免费成人在线观看视频| 国产一区二区在线免费观看| 国产成人精品aa毛片| 成人h动漫精品| 在线看国产日韩| 91精品视频网| 久久久久久久久伊人| 国产精品天美传媒沈樵| 一区二区三区免费| 日本aⅴ亚洲精品中文乱码| 欧美三级电影网| 欧美乱熟臀69xxxxxx| 久久久亚洲国产美女国产盗摄 | 国产精品美女久久久久久久网站| 亚洲三级免费电影| 午夜久久久久久| 国产一区二区日韩精品| 色综合激情久久| 日韩一区二区免费高清| 国产精品二三区| 日韩成人av影视| 成人av动漫网站| 在线不卡a资源高清| 久久先锋影音av| 亚洲美女免费在线| 免费久久99精品国产| 不卡的电影网站| 制服丝袜亚洲色图| 国产精品美女久久久久久久久久久| 亚洲综合色视频| 国内不卡的二区三区中文字幕| 91在线看国产| 精品欧美黑人一区二区三区| 一区二区三区在线视频免费| 久久精品国产精品青草| 日本韩国精品一区二区在线观看| 日韩一二三区视频| 亚洲精品视频自拍| 国产一区在线精品| 在线视频欧美精品| 久久久不卡网国产精品一区| 亚洲一区在线观看免费| 日韩三区在线观看| 一区二区三区在线高清| 国产成人久久精品77777最新版本| 欧美日韩一区二区三区四区| 日本一区二区三级电影在线观看 | 国产成人午夜精品5599| 欧美一区二区三区喷汁尤物| 亚洲精品一二三| 丁香六月综合激情| 欧美成人精品福利| 亚洲.国产.中文慕字在线| av亚洲精华国产精华| 久久久久一区二区三区四区| 日本不卡1234视频| 7777精品伊人久久久大香线蕉最新版| 日韩一区在线看| 成人精品小蝌蚪| 久久久久高清精品| 精品一区二区三区视频在线观看| 欧美日韩不卡视频| 亚洲一区二区五区| 在线一区二区视频| 亚洲三级小视频| 99re成人精品视频| 亚洲色图在线视频| 色综合久久天天综合网| 国产精品羞羞答答xxdd| 欧美精品一区二区三区高清aⅴ| 美女国产一区二区三区|