Package quicktime.app.time

Source Code of quicktime.app.time.TaskThread

/*     */ package quicktime.app.time;
/*     */
/*     */ import java.security.AccessController;
/*     */ import java.security.PrivilegedAction;
/*     */ import java.util.Enumeration;
/*     */ import java.util.Vector;
/*     */ import quicktime.QTException;
/*     */ import quicktime.QTRuntimeException;
/*     */ import quicktime.QTSession;
/*     */
/*     */ public class TaskThread
/*     */   implements Runnable
/*     */ {
/*     */   private static final int PRIORITY_NOT_SET = -1;
/*  95 */   private Vector taskVector = new Vector(12, 0);
/*  96 */   private Thread theThread = null;
/*     */   private int sleepTime;
/*     */   private String tName;
/*  99 */   private int threadPriority = 5;
/*     */
/* 246 */   private boolean threadIsRunning = false;
/* 247 */   private static Vector threads = new Vector();
/*     */
/*     */   public static final void killAllThreads()
/*     */   {
/*  58 */     Enumeration localEnumeration = threads.elements();
/*  59 */     while (localEnumeration.hasMoreElements()) {
/*  60 */       TaskThread localTaskThread = (TaskThread)localEnumeration.nextElement();
/*  61 */       localTaskThread.stop();
/*  62 */       localTaskThread.removeAll();
/*     */     }
/*  64 */     while (!threads.isEmpty())
/*     */     {
/*  66 */       Thread.yield();
/*     */     }
/*     */   }
/*     */
/*     */   public TaskThread(String paramString)
/*     */   {
/*  80 */     this(paramString, 100);
/*     */   }
/*     */
/*     */   public TaskThread(String paramString, int paramInt)
/*     */   {
/*  90 */     this.sleepTime = paramInt;
/*  91 */     this.tName = paramString;
/*     */   }
/*     */
/*     */   public int getSleepTime()
/*     */   {
/* 104 */     return this.sleepTime;
/*     */   }
/*     */
/*     */   public void setSleepTime(int paramInt)
/*     */   {
/* 109 */     this.sleepTime = paramInt;
/*     */   }
/*     */
/*     */   public boolean addMember(Object paramObject)
/*     */   {
/* 116 */     if (!isAppropriate(paramObject)) return false;
/*     */
/* 118 */     if (this.taskVector.contains(paramObject)) return true;
/* 119 */     Taskable localTaskable = (Taskable)paramObject;
/* 120 */     if (localTaskable.getTasker() != null) {
/* 121 */       localTaskable.getTasker().removeMember(paramObject);
/*     */     }
/* 123 */     this.taskVector.addElement(paramObject);
/*     */
/* 125 */     localTaskable.addedToTasker(this);
/* 126 */     return true;
/*     */   }
/*     */
/*     */   public boolean isAppropriate(Object paramObject)
/*     */   {
/* 134 */     return paramObject instanceof Taskable;
/*     */   }
/*     */
/*     */   public Enumeration members()
/*     */   {
/* 142 */     return this.taskVector.elements();
/*     */   }
/*     */
/*     */   public void addAndStart(Taskable paramTaskable)
/*     */   {
/* 151 */     addMember(paramTaskable);
/* 152 */     start();
/*     */   }
/*     */
/*     */   public void removeMember(Object paramObject)
/*     */   {
/* 161 */     if (paramObject != null)
/*     */     {
/* 163 */       this.taskVector.removeElement(paramObject);
/*     */     }
/*     */
/* 166 */     ((Taskable)paramObject).removedFromTasker();
/*     */   }
/*     */
/*     */   public void removeAll()
/*     */   {
/* 173 */     stop();
/* 174 */     synchronized (this) {
/* 175 */       for (Enumeration localEnumeration = this.taskVector.elements(); localEnumeration.hasMoreElements(); ) {
/* 176 */         Taskable localTaskable = (Taskable)localEnumeration.nextElement();
/* 177 */         localTaskable.removedFromTasker();
/*     */       }
/* 179 */       this.taskVector.removeAllElements();
/*     */     }
/*     */   }
/*     */
/*     */   public int size()
/*     */   {
/* 186 */     return this.taskVector.size();
/*     */   }
/*     */
/*     */   public boolean hasMember(Object paramObject)
/*     */   {
/* 192 */     return this.taskVector.contains(paramObject);
/*     */   }
/*     */
/*     */   public boolean isEmpty()
/*     */   {
/* 197 */     return this.taskVector.isEmpty();
/*     */   }
/*     */
/*     */   public void start()
/*     */   {
/* 203 */     if (this.theThread == null) {
/* 204 */       if (QTSession.getJavaVersion() == 65537) {
/* 205 */         this.theThread = new Thread(this, this.tName);
/*     */       }
/*     */       else
/*     */       {
/* 217 */         this.theThread = ((Thread)new Object()
/*     */         {
/*     */           Object doPrivelegedAction()
/*     */           {
/* 209 */             return AccessController.doPrivileged(new PrivilegedAction()
/*     */             {
/*     */               public Object run() {
/* 212 */                 return new Thread(TaskThread.this, TaskThread.this.tName);
/*     */               }
/*     */             });
/*     */           }
/*     */         }
/* 217 */         .doPrivelegedAction());
/*     */       }
/*     */
/* 220 */       if (this.threadPriority != -1)
/* 221 */         setPriority(this.threadPriority);
/* 222 */       this.threadIsRunning = true;
/* 223 */       this.theThread.start();
/* 224 */       threads.addElement(this);
/*     */     }
/*     */   }
/*     */
/*     */   public void stop()
/*     */   {
/* 234 */     if (this.theThread != null) {
/* 235 */       synchronized (this.theThread)
/*     */       {
/* 237 */         this.threadIsRunning = false;
/*     */
/* 239 */         this.theThread.resume();
/* 240 */         this.theThread.interrupt();
/*     */       }
/* 242 */       this.theThread = null;
/*     */     }
/*     */   }
/*     */
/*     */   public void suspend()
/*     */   {
/* 250 */     if (this.theThread != null) this.theThread.suspend();
/*     */   }
/*     */
/* 253 */   public void resume() { if (this.theThread != null) this.theThread.resume();
/*     */   }
/*     */
/*     */   public boolean isAlive()
/*     */   {
/* 257 */     return (this.theThread != null) && (this.theThread.isAlive());
/*     */   }
/*     */
/*     */   public int getPriority()
/*     */   {
/* 265 */     return this.theThread != null ? this.theThread.getPriority() : this.threadPriority;
/*     */   }
/*     */
/*     */   public void setPriority(int paramInt)
/*     */   {
/* 272 */     if (this.theThread != null) this.theThread.setPriority(paramInt);
/* 273 */     this.threadPriority = paramInt;
/*     */   }
/*     */
/*     */   public void run()
/*     */   {
/*     */     while (true) {
/* 281 */       if ((this.threadIsRunning) && (this.taskVector.size() > 0)) {
/* 282 */         synchronized (this.theThread) {
/* 283 */           if (!this.threadIsRunning)
/*     */             break label263;
/* 285 */           for (int i = 0; i < this.taskVector.size(); i++) {
/*     */             try {
/* 287 */               Taskable localTaskable = (Taskable)this.taskVector.elementAt(i);
/*     */
/* 289 */               int j = 1;
/*     */               try {
/* 291 */                 if (!this.threadIsRunning)
/*     */                 {
/* 299 */                   if (j != 0) {
/* 300 */                     threads.removeElement(this);
/* 301 */                     this.theThread = null;
/*     */                   }
/* 303 */                   break;
/*     */                 }
/* 293 */                 localTaskable.task();
/* 294 */                 j = 0;
/*     */               } catch (QTException localQTException) {
/* 296 */                 QTRuntimeException.handleOrThrow(new QTRuntimeException(localQTException), localTaskable, "task");
/* 297 */                 j = 0;
/*     */               } finally {
/* 299 */                 if (j != 0) {
/* 300 */                   threads.removeElement(this);
/* 301 */                   this.theThread = null;
/*     */                 }
/*     */               }
/*     */             } catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException) {
/* 305 */               break;
/*     */             }
/*     */           }
/*     */         }
/* 309 */         if (this.threadIsRunning)
/*     */           try
/*     */           {
/* 312 */             if (this.sleepTime < 1) Thread.yield(); else
/* 313 */               Thread.sleep(this.sleepTime);
/*     */           }
/*     */           catch (InterruptedException localInterruptedException)
/*     */           {
/* 317 */             if (!this.threadIsRunning)
/* 318 */               break label263;
/*     */           }
/*     */       }
/*     */     }
/* 322 */     label263: threads.removeElement(this);
/* 323 */     this.theThread = null;
/*     */   }
/*     */
/*     */   protected void finalize() throws Throwable {
/* 327 */     removeAll();
/* 328 */     super.finalize();
/*     */   }
/*     */
/*     */   public String toString()
/*     */   {
/* 333 */     return getClass().getName() + "[name=" + this.tName + ",size=" + size() + ",priority=" + getPriority() + ",sleepTime=" + this.sleepTime + "]";
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\QTJava.zip
* Qualified Name:     quicktime.app.time.TaskThread
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of quicktime.app.time.TaskThread

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.