home *** CD-ROM | disk | FTP | other *** search
/ Print Shop Ensemble 3 / the-print-shop-ensemble-iii.iso / worldnet / disk2 / java.z / MOZ2_01.ZIP / java / lang / Thread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-08  |  6.2 KB  |  248 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.    public static final int MIN_PRIORITY = 1;
  17.    public static final int NORM_PRIORITY = 5;
  18.    public static final int MAX_PRIORITY = 10;
  19.  
  20.    private static synchronized int nextThreadNum() {
  21.       return threadInitNumber++;
  22.    }
  23.  
  24.    public static native Thread currentThread();
  25.  
  26.    public static native void yield();
  27.  
  28.    public static native void sleep(long var0) throws InterruptedException;
  29.  
  30.    public static void sleep(long millis, int nanos) throws InterruptedException {
  31.       if (nanos > 500000) {
  32.          ++millis;
  33.       }
  34.  
  35.       sleep(millis);
  36.    }
  37.  
  38.    private void init(ThreadGroup g, Runnable target, String name) {
  39.       Thread parent = currentThread();
  40.       if (g == null) {
  41.          g = parent.getThreadGroup();
  42.       } else {
  43.          g.checkAccess();
  44.       }
  45.  
  46.       this.group = g;
  47.       this.daemon = parent.isDaemon();
  48.       this.priority = parent.getPriority();
  49.       this.name = name.toCharArray();
  50.       this.target = target;
  51.       this.setPriority0(this.priority);
  52.       g.add(this);
  53.    }
  54.  
  55.    public Thread() {
  56.       this.init((ThreadGroup)null, (Runnable)null, "Thread-" + nextThreadNum());
  57.    }
  58.  
  59.    public Thread(Runnable target) {
  60.       this.init((ThreadGroup)null, target, "Thread-" + nextThreadNum());
  61.    }
  62.  
  63.    public Thread(ThreadGroup group, Runnable target) {
  64.       this.init(group, target, "Thread-" + nextThreadNum());
  65.    }
  66.  
  67.    public Thread(String name) {
  68.       this.init((ThreadGroup)null, (Runnable)null, name);
  69.    }
  70.  
  71.    public Thread(ThreadGroup group, String name) {
  72.       this.init(group, (Runnable)null, name);
  73.    }
  74.  
  75.    public Thread(Runnable target, String name) {
  76.       this.init((ThreadGroup)null, target, name);
  77.    }
  78.  
  79.    public Thread(ThreadGroup group, Runnable target, String name) {
  80.       this.init(group, target, name);
  81.    }
  82.  
  83.    public synchronized native void start();
  84.  
  85.    public void run() {
  86.       if (this.target != null) {
  87.          this.target.run();
  88.       }
  89.  
  90.    }
  91.  
  92.    private void exit() {
  93.       if (this.group != null) {
  94.          this.group.remove(this);
  95.          this.group = null;
  96.       }
  97.  
  98.    }
  99.  
  100.    public final void stop() {
  101.       this.stop(new ThreadDeath());
  102.    }
  103.  
  104.    public final synchronized void stop(Throwable o) {
  105.       this.checkAccess();
  106.       this.stop0(o);
  107.    }
  108.  
  109.    public void interrupt() {
  110.       throw new NoSuchMethodError();
  111.    }
  112.  
  113.    public static boolean interrupted() {
  114.       throw new NoSuchMethodError();
  115.    }
  116.  
  117.    public boolean isInterrupted() {
  118.       throw new NoSuchMethodError();
  119.    }
  120.  
  121.    public void destroy() {
  122.       throw new NoSuchMethodError();
  123.    }
  124.  
  125.    public final native boolean isAlive();
  126.  
  127.    public final void suspend() {
  128.       this.checkAccess();
  129.       this.suspend0();
  130.    }
  131.  
  132.    public final void resume() {
  133.       this.checkAccess();
  134.       this.resume0();
  135.    }
  136.  
  137.    public final void setPriority(int newPriority) {
  138.       this.checkAccess();
  139.       if (newPriority <= 10 && newPriority >= 1) {
  140.          if (newPriority > this.group.getMaxPriority()) {
  141.             newPriority = this.group.getMaxPriority();
  142.          }
  143.  
  144.          this.setPriority0(this.priority = newPriority);
  145.       } else {
  146.          throw new IllegalArgumentException();
  147.       }
  148.    }
  149.  
  150.    public final int getPriority() {
  151.       return this.priority;
  152.    }
  153.  
  154.    public final void setName(String name) {
  155.       this.checkAccess();
  156.       this.name = name.toCharArray();
  157.    }
  158.  
  159.    public final String getName() {
  160.       return String.valueOf(this.name);
  161.    }
  162.  
  163.    public final ThreadGroup getThreadGroup() {
  164.       return this.group;
  165.    }
  166.  
  167.    public static int activeCount() {
  168.       return currentThread().getThreadGroup().activeCount();
  169.    }
  170.  
  171.    public static int enumerate(Thread[] tarray) {
  172.       return currentThread().getThreadGroup().enumerate(tarray);
  173.    }
  174.  
  175.    public native int countStackFrames();
  176.  
  177.    public final synchronized void join(long millis) throws InterruptedException {
  178.       long base = System.currentTimeMillis();
  179.       long now = 0L;
  180.       if (millis == 0L) {
  181.          while(this.isAlive()) {
  182.             this.wait(0L);
  183.          }
  184.  
  185.       } else {
  186.          while(this.isAlive()) {
  187.             long delay = millis - now;
  188.             if (delay <= 0L) {
  189.                break;
  190.             }
  191.  
  192.             this.wait(delay);
  193.             now = System.currentTimeMillis() - base;
  194.          }
  195.  
  196.       }
  197.    }
  198.  
  199.    public final synchronized void join(long millis, int nanos) throws InterruptedException {
  200.       if (nanos >= 500000 || millis == 0L) {
  201.          ++millis;
  202.       }
  203.  
  204.       this.join(millis);
  205.    }
  206.  
  207.    public final void join() throws InterruptedException {
  208.       this.join(0L);
  209.    }
  210.  
  211.    public static void dumpStack() {
  212.       (new Exception("Stack trace")).printStackTrace();
  213.    }
  214.  
  215.    public final void setDaemon(boolean on) {
  216.       this.checkAccess();
  217.       if (this.isAlive()) {
  218.          throw new IllegalThreadStateException();
  219.       } else {
  220.          this.daemon = on;
  221.       }
  222.    }
  223.  
  224.    public final boolean isDaemon() {
  225.       return this.daemon;
  226.    }
  227.  
  228.    public void checkAccess() {
  229.       SecurityManager security = System.getSecurityManager();
  230.       if (security != null) {
  231.          security.checkAccess(this);
  232.       }
  233.  
  234.    }
  235.  
  236.    public String toString() {
  237.       return "Thread[" + this.getName() + "," + this.getPriority() + "," + this.getThreadGroup().getName() + "]";
  238.    }
  239.  
  240.    private native void setPriority0(int var1);
  241.  
  242.    private native void stop0(Object var1);
  243.  
  244.    private native void suspend0();
  245.  
  246.    private native void resume0();
  247. }
  248.