home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 July / PCO_07_97.ISO / NET_COM / cc32e40.exe / nav40.z / java40.jar / java / lang / Thread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-07  |  5.3 KB  |  289 lines

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