home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 31 / SUPERCDa.iso / Inet / HotJava / hjava.exe / Windows / resource / jre / lib / rt.jar / java / lang / Thread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-11  |  5.6 KB  |  285 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.       synchronized(this){}
  116.  
  117.       try {
  118.          this.checkAccess();
  119.          this.resume();
  120.          this.stop0(new ThreadDeath());
  121.       } catch (Throwable var3) {
  122.          throw var3;
  123.       }
  124.  
  125.    }
  126.  
  127.    public final synchronized void stop(Throwable var1) {
  128.       this.checkAccess();
  129.       this.resume();
  130.       this.stop0(var1);
  131.    }
  132.  
  133.    public void interrupt() {
  134.       this.checkAccess();
  135.       this.interrupt0();
  136.    }
  137.  
  138.    public static boolean interrupted() {
  139.       return currentThread().isInterrupted(true);
  140.    }
  141.  
  142.    public boolean isInterrupted() {
  143.       return this.isInterrupted(false);
  144.    }
  145.  
  146.    private native boolean isInterrupted(boolean var1);
  147.  
  148.    public void destroy() {
  149.       throw new NoSuchMethodError();
  150.    }
  151.  
  152.    public final native boolean isAlive();
  153.  
  154.    public final void suspend() {
  155.       this.checkAccess();
  156.       this.suspend0();
  157.    }
  158.  
  159.    public final void resume() {
  160.       this.checkAccess();
  161.       this.resume0();
  162.    }
  163.  
  164.    public final void setPriority(int var1) {
  165.       this.checkAccess();
  166.       if (var1 <= 10 && var1 >= 1) {
  167.          if (var1 > this.group.getMaxPriority()) {
  168.             var1 = this.group.getMaxPriority();
  169.          }
  170.  
  171.          this.setPriority0(this.priority = var1);
  172.       } else {
  173.          throw new IllegalArgumentException();
  174.       }
  175.    }
  176.  
  177.    public final int getPriority() {
  178.       return this.priority;
  179.    }
  180.  
  181.    public final void setName(String var1) {
  182.       this.checkAccess();
  183.       this.name = var1.toCharArray();
  184.    }
  185.  
  186.    public final String getName() {
  187.       return String.valueOf(this.name);
  188.    }
  189.  
  190.    public final ThreadGroup getThreadGroup() {
  191.       return this.group;
  192.    }
  193.  
  194.    public static int activeCount() {
  195.       return currentThread().getThreadGroup().activeCount();
  196.    }
  197.  
  198.    public static int enumerate(Thread[] var0) {
  199.       return currentThread().getThreadGroup().enumerate(var0);
  200.    }
  201.  
  202.    public native int countStackFrames();
  203.  
  204.    public final synchronized void join(long var1) throws InterruptedException {
  205.       long var3 = System.currentTimeMillis();
  206.       long var5 = 0L;
  207.       if (var1 < 0L) {
  208.          throw new IllegalArgumentException("timeout value is negative");
  209.       } else if (var1 == 0L) {
  210.          while(this.isAlive()) {
  211.             this.wait(0L);
  212.          }
  213.  
  214.       } else {
  215.          while(this.isAlive()) {
  216.             long var7 = var1 - var5;
  217.             if (var7 <= 0L) {
  218.                break;
  219.             }
  220.  
  221.             this.wait(var7);
  222.             var5 = System.currentTimeMillis() - var3;
  223.          }
  224.  
  225.       }
  226.    }
  227.  
  228.    public final synchronized void join(long var1, int var3) throws InterruptedException {
  229.       if (var1 < 0L) {
  230.          throw new IllegalArgumentException("timeout value is negative");
  231.       } else if (var3 >= 0 && var3 <= 999999) {
  232.          if (var3 >= 500000 || var3 != 0 && var1 == 0L) {
  233.             ++var1;
  234.          }
  235.  
  236.          this.join(var1);
  237.       } else {
  238.          throw new IllegalArgumentException("nanosecond timeout value out of range");
  239.       }
  240.    }
  241.  
  242.    public final void join() throws InterruptedException {
  243.       this.join(0L);
  244.    }
  245.  
  246.    public static void dumpStack() {
  247.       (new Exception("Stack trace")).printStackTrace();
  248.    }
  249.  
  250.    public final void setDaemon(boolean var1) {
  251.       this.checkAccess();
  252.       if (this.isAlive()) {
  253.          throw new IllegalThreadStateException();
  254.       } else {
  255.          this.daemon = var1;
  256.       }
  257.    }
  258.  
  259.    public final boolean isDaemon() {
  260.       return this.daemon;
  261.    }
  262.  
  263.    public void checkAccess() {
  264.       SecurityManager var1 = System.getSecurityManager();
  265.       if (var1 != null) {
  266.          var1.checkAccess(this);
  267.       }
  268.  
  269.    }
  270.  
  271.    public String toString() {
  272.       return this.getThreadGroup() != null ? "Thread[" + this.getName() + "," + this.getPriority() + "," + this.getThreadGroup().getName() + "]" : "Thread[" + this.getName() + "," + this.getPriority() + "," + "" + "]";
  273.    }
  274.  
  275.    private native void setPriority0(int var1);
  276.  
  277.    private native void stop0(Object var1);
  278.  
  279.    private native void suspend0();
  280.  
  281.    private native void resume0();
  282.  
  283.    private native void interrupt0();
  284. }
  285.