1 package example; 2 3 import java.util.logging.Logger ; 4 import java.util.logging.Level ; 5 6 import javax.resource.spi.work.Work ; 7 8 11 public class WorkTask implements Work { 12 private static final Logger log = 13 Logger.getLogger(WorkTask.class.getName()); 14 15 private WorkResource _resource; 16 17 private volatile boolean _isActive = true; 19 20 23 WorkTask(WorkResource resource) 24 { 25 _resource = resource; 26 } 27 28 31 public void run() 32 { 33 log.fine("work starting"); 34 35 while (_isActive) { 36 log.fine("work adding count"); 37 38 _resource.addCount(); 39 40 try { 41 synchronized (this) { 42 wait(_resource.getSleepTime()); 43 } 44 } catch (Throwable e) { 45 log.log(Level.WARNING, e.toString(), e); 46 } 47 } 48 49 log.fine("work complete"); 50 } 51 52 56 public void release() 57 { 58 _isActive = false; 59 60 synchronized (this) { 61 notifyAll(); 62 } 63 } 64 } 65 | Popular Tags |