1 64 65 package com.jcorporate.expresso.services.asyncprocess; 66 67 72 73 import com.jcorporate.expresso.core.registry.ExpressoThread; 74 75 import java.util.LinkedList ; 76 77 public class ProcessThread extends ExpressoThread { 78 private boolean done = false; 79 80 83 DefaultAsyncProcessor parent; 84 85 88 DefaultAsyncProcessor.ProcessWrapper curProcess = null; 89 90 94 Object writeLock = new Object (); 95 96 103 public ProcessThread(DefaultAsyncProcessor processor, ThreadGroup group, String name) { 104 super(group, name); 105 parent = processor; 106 } 107 108 111 public void interrupt() { 112 done = true; 113 synchronized (writeLock) { 114 if (curProcess != null) { 115 curProcess.getWrappedObject().kill(); 116 } 117 } 118 119 super.interrupt(); 120 } 121 122 126 public void run() { 127 super.run(); 128 129 LinkedList queue = parent.getQueue(); 130 while (!done) { 131 synchronized (queue) { 132 if (queue.size() == 0) { 133 try { 134 queue.wait(); 135 } catch (InterruptedException ex) { 136 if (done) { 137 return; 138 } 139 140 continue; 141 } 142 synchronized (writeLock) { 143 curProcess = (DefaultAsyncProcessor.ProcessWrapper) queue.removeFirst(); 144 } 145 } 146 } 147 148 curProcess.process(); 149 150 synchronized (writeLock) { 151 curProcess = null; 152 } 153 } 154 } 155 } 156 | Popular Tags |