GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — JavaInterview/java/src/JavaBasic/HighLowPriority.java at master · damaohongtu/JavaInterview Expand file tree/ Copy pathHighLowPriority.javaMore file actions 53 lines (50 loc) · 1.32 KB / Copy pathHighLowPriority.javaFile metadata and controls53 lines (50 loc) · 1.32 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 package JavaBasic;/** * @Classname HighLowPriority * @Description TODO * @Date 19-5-25 下午1:46 * @Created by mao<[email protected]> */ public class HighLowPriority { public static void main(String[] args){ Thread.currentThread().setPriority(Thread.MAX_PRIORITY); Clicker high=new Clicker(Thread.NORM_PRIORITY+2); Clicker low=new Clicker(Thread.NORM_PRIORITY-2); high.start(); low.start(); try { Thread.sleep(1000); }catch (InterruptedException e){ System.out.println("Main thread interrupted"); } high.stop(); low.stop(); // try{ // high.t.join(); // low.t.join(); // }catch (InterruptedException e){ // System.out.println("Interrupt exception caught"); // } System.out.println("low priority clicker:"+low.click); System.out.println("high priority clicker:"+high.click); } } class Clicker implements Runnable{ int click=0; Thread t; private volatile boolean running=true; public Clicker(int p){ t=new Thread(this); t.setPriority(p); } public void run(){ while (running){ click++; } } public void stop(){ running=false; } public void start(){ t.start(); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |