📄 workresource.java
字号:
package example;import java.util.logging.Logger;import javax.resource.spi.ResourceAdapter;import javax.resource.spi.ResourceAdapterInternalException;import javax.resource.spi.BootstrapContext;import javax.resource.spi.work.Work;import javax.resource.spi.work.WorkManager;import javax.resource.spi.work.WorkException;import com.caucho.jca.AbstractResourceAdapter;/** * Implements a resource which uses uses Work management for * separate threading. */public class WorkResource extends AbstractResourceAdapter { private static final Logger log = Logger.getLogger(WorkResource.class.getName()); // The time in milliseconds the resource should sleep private long _sleepTime = 10000L; // The count of times the server has looped private int _count; /** * Returns the sleep time. */ public long getSleepTime() { return _sleepTime; } /** * Adds to the count. */ public void addCount() { _count++; } /** * The start method is called when the resource adapter starts, i.e. * when the web-app or host initializes. */ public void start(BootstrapContext ctx) throws ResourceAdapterInternalException { log.info("WorkResource[] starting"); WorkManager workManager = ctx.getWorkManager(); Work work = new WorkTask(this); try { // Submits the work, but does not wait for the result. // In other words, it spawns a new thread workManager.startWork(work); } catch (WorkException e) { throw new ResourceAdapterInternalException(e); } } /** * Called when the resource adapter is stopped, i.e. when the * web-app or host closes down. */ public void stop() throws ResourceAdapterInternalException { log.info("Resource[" + _count + "] stopping"); } /** * Returns a printable version of the resource. */ public String toString() { return "WorkResource[" + _count + "]"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -