home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / lang / Thread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.9 KB  |  346 lines

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