1 28 29 package com.caucho.jca; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 import com.caucho.util.ThreadTask; 34 35 import javax.resource.spi.work.Work ; 36 import javax.resource.spi.work.WorkEvent ; 37 import javax.resource.spi.work.WorkListener ; 38 import java.util.logging.Logger ; 39 40 43 public class WorkThread implements ThreadTask { 44 private static final L10N L = new L10N(WorkThread.class); 45 private static final Logger log = Log.open(WorkThread.class); 46 47 private boolean _isStarted; 48 private WorkManagerImpl _manager; 49 private ClassLoader _classLoader; 50 private Work _work; 51 private WorkListener _listener; 52 53 56 WorkThread(WorkManagerImpl manager, Work work, 57 ClassLoader classLoader, WorkListener listener) 58 { 59 _manager = manager; 60 _work = work; 61 _classLoader = classLoader; 62 _listener = listener; 63 } 64 65 68 public boolean isStarted() 69 { 70 return _isStarted; 71 } 72 73 76 public void run() 77 { 78 Thread thread = Thread.currentThread(); 79 thread.setContextClassLoader(_classLoader); 80 81 _isStarted = true; 82 83 try { 84 synchronized (this) { 85 notifyAll(); 86 } 87 } catch (Exception e) { 88 } 89 90 try { 91 _work.run(); 92 93 if (_listener != null) 94 _listener.workCompleted(new WorkEvent (_manager, 95 WorkEvent.WORK_COMPLETED, 96 _work, null, 0)); 97 } finally { 98 _manager.completeWork(_work); 99 } 100 } 101 } 102 | Popular Tags |