home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / lang / Thread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  5.5 KB  |  276 lines

  1. package java.lang;
  2.  
  3. public class Thread implements Runnable {
  4.    private char[] name;
  5.    private int priority;
  6.    private Thread threadQ;
  7.    private int PrivateInfo;
  8.    private int eetop;
  9.    private boolean single_step;
  10.    private boolean daemon = false;
  11.    private boolean stillborn = false;
  12.    private Runnable target;
  13.    private static Thread activeThreadQ;
  14.    private ThreadGroup group;
  15.    private static int threadInitNumber;
  16.    private int initial_stack_memory;
  17.    public static final int MIN_PRIORITY = 1;
  18.    public static final int NORM_PRIORITY = 5;
  19.    public static final int MAX_PRIORITY = 10;
  20.  
  21.    private static synchronized int nextThreadNum() {
  22.       return threadInitNumber++;
  23.    }
  24.  
  25.    public static native Thread currentThread();
  26.  
  27.    public static native void yield();
  28.  
  29.    public static native void sleep(long var0) throws InterruptedException;
  30.  
  31.    public static void sleep(long var0, int var2) throws InterruptedException {
  32.       if (var0 < 0L) {
  33.          throw new IllegalArgumentException("timeout value is negative");
  34.       } else if (var2 >= 0 && var2 <= 999999) {
  35.          if (var2 >= 500000 || var2 != 0 && var0 == 0L) {
  36.             ++var0;
  37.          }
  38.  
  39.          sleep(var0);
  40.       } else {
  41.          throw new IllegalArgumentException("nanosecond timeout value out of range");
  42.       }
  43.    }
  44.  
  45.    private void init(ThreadGroup var1, Runnable var2, String var3) {
  46.       Thread var4 = currentThread();
  47.       if (var1 == null) {
  48.          SecurityManager var5 = System.getSecurityManager();
  49.          if (var5 != null) {
  50.             var1 = var5.getThreadGroup();
  51.          }
  52.  
  53.          if (var1 == null) {
  54.             var1 = var4.getThreadGroup();
  55.          }
  56.       }
  57.  
  58.       var1.checkAccess();
  59.       this.group = var1;
  60.       this.daemon = var4.isDaemon();
  61.       this.priority = var4.getPriority();
  62.       this.name = var3.toCharArray();
  63.       this.target = var2;
  64.       this.setPriority(this.priority);
  65.       var1.add(this);
  66.    }
  67.  
  68.    public Thread() {
  69.       this.init((ThreadGroup)null, (Runnable)null, "Thread-" + nextThreadNum());
  70.    }
  71.  
  72.    public Thread(Runnable var1) {
  73.       this.init((ThreadGroup)null, var1, "Thread-" + nextThreadNum());
  74.    }
  75.  
  76.    public Thread(ThreadGroup var1, Runnable var2) {
  77.       this.init(var1, var2, "Thread-" + nextThreadNum());
  78.    }
  79.  
  80.    public Thread(String var1) {
  81.       this.init((ThreadGroup)null, (Runnable)null, var1);
  82.    }
  83.  
  84.    public Thread(ThreadGroup var1, String var2) {
  85.       this.init(var1, (Runnable)null, var2);
  86.    }
  87.  
  88.    public Thread(Runnable var1, String var2) {
  89.       this.init((ThreadGroup)null, var1, var2);
  90.    }
  91.  
  92.    public Thread(ThreadGroup var1, Runnable var2, String var3) {
  93.       this.init(var1, var2, var3);
  94.    }
  95.  
  96.    public synchronized native void start();
  97.  
  98.    public void run() {
  99.       if (this.target != null) {
  100.          this.target.run();
  101.       }
  102.  
  103.    }
  104.  
  105.    private void exit() {
  106.       if (this.group != null) {
  107.          this.group.remove(this);
  108.          this.group = null;
  109.       }
  110.  
  111.       this.target = null;
  112.    }
  113.  
  114.    public final void stop() {
  115.       this.stop(new ThreadDeath());
  116.    }
  117.  
  118.    public final synchronized void stop(Throwable var1) {
  119.       this.checkAccess();
  120.       this.resume();
  121.       this.stop0(var1);
  122.    }
  123.  
  124.    public void interrupt() {
  125.       this.checkAccess();
  126.       this.interrupt0();
  127.    }
  128.  
  129.    public static boolean interrupted() {
  130.       return currentThread().isInterrupted(true);
  131.    }
  132.  
  133.    public boolean isInterrupted() {
  134.       return this.isInterrupted(false);
  135.    }
  136.  
  137.    private native boolean isInterrupted(boolean var1);
  138.  
  139.    public void destroy() {
  140.       throw new NoSuchMethodError();
  141.    }
  142.  
  143.    public final native boolean isAlive();
  144.  
  145.    public final void suspend() {
  146.       this.checkAccess();
  147.       this.suspend0();
  148.    }
  149.  
  150.    public final void resume() {
  151.       this.checkAccess();
  152.       this.resume0();
  153.    }
  154.  
  155.    public final void setPriority(int var1) {
  156.       this.checkAccess();
  157.       if (var1 <= 10 && var1 >= 1) {
  158.          if (var1 > this.group.getMaxPriority()) {
  159.             var1 = this.group.getMaxPriority();
  160.          }
  161.  
  162.          this.setPriority0(this.priority = var1);
  163.       } else {
  164.          throw new IllegalArgumentException();
  165.       }
  166.    }
  167.  
  168.    public final int getPriority() {
  169.       return this.priority;
  170.    }
  171.  
  172.    public final void setName(String var1) {
  173.       this.checkAccess();
  174.       this.name = var1.toCharArray();
  175.    }
  176.  
  177.    public final String getName() {
  178.       return String.valueOf(this.name);
  179.    }
  180.  
  181.    public final ThreadGroup getThreadGroup() {
  182.       return this.group;
  183.    }
  184.  
  185.    public static int activeCount() {
  186.       return currentThread().getThreadGroup().activeCount();
  187.    }
  188.  
  189.    public static int enumerate(Thread[] var0) {
  190.       return currentThread().getThreadGroup().enumerate(var0);
  191.    }
  192.  
  193.    public native int countStackFrames();
  194.  
  195.    public final synchronized void join(long var1) throws InterruptedException {
  196.       long var3 = System.currentTimeMillis();
  197.       long var5 = 0L;
  198.       if (var1 < 0L) {
  199.          throw new IllegalArgumentException("timeout value is negative");
  200.       } else if (var1 == 0L) {
  201.          while(this.isAlive()) {
  202.             this.wait(0L);
  203.          }
  204.  
  205.       } else {
  206.          while(this.isAlive()) {
  207.             long var7 = var1 - var5;
  208.             if (var7 <= 0L) {
  209.                break;
  210.             }
  211.  
  212.             this.wait(var7);
  213.             var5 = System.currentTimeMillis() - var3;
  214.          }
  215.  
  216.       }
  217.    }
  218.  
  219.    public final synchronized void join(long var1, int var3) throws InterruptedException {
  220.       if (var1 < 0L) {
  221.          throw new IllegalArgumentException("timeout value is negative");
  222.       } else if (var3 >= 0 && var3 <= 999999) {
  223.          if (var3 >= 500000 || var3 != 0 && var1 == 0L) {
  224.             ++var1;
  225.          }
  226.  
  227.          this.join(var1);
  228.       } else {
  229.          throw new IllegalArgumentException("nanosecond timeout value out of range");
  230.       }
  231.    }
  232.  
  233.    public final void join() throws InterruptedException {
  234.       this.join(0L);
  235.    }
  236.  
  237.    public static void dumpStack() {
  238.       (new Exception("Stack trace")).printStackTrace();
  239.    }
  240.  
  241.    public final void setDaemon(boolean var1) {
  242.       this.checkAccess();
  243.       if (this.isAlive()) {
  244.          throw new IllegalThreadStateException();
  245.       } else {
  246.          this.daemon = var1;
  247.       }
  248.    }
  249.  
  250.    public final boolean isDaemon() {
  251.       return this.daemon;
  252.    }
  253.  
  254.    public void checkAccess() {
  255.       SecurityManager var1 = System.getSecurityManager();
  256.       if (var1 != null) {
  257.          var1.checkAccess(this);
  258.       }
  259.  
  260.    }
  261.  
  262.    public String toString() {
  263.       return this.getThreadGroup() != null ? "Thread[" + this.getName() + "," + this.getPriority() + "," + this.getThreadGroup().getName() + "]" : "Thread[" + this.getName() + "," + this.getPriority() + "," + "" + "]";
  264.    }
  265.  
  266.    private native void setPriority0(int var1);
  267.  
  268.    private native void stop0(Object var1);
  269.  
  270.    private native void suspend0();
  271.  
  272.    private native void resume0();
  273.  
  274.    private native void interrupt0();
  275. }
  276.