Java后台作业执行组件:jesque
jopen
10年前
jesque 是 Resque 的Java语言实现版。
它完全可与Ruby和Node.js的(Coffee-Resque))实现进行互操作。resque是基于redis的后台任务组件,能把任何类或模块作为任务在后台执行,且自带前台管理功能,方便查看执行情况。
Jesque 是一个 Maven 项目,依赖于 Jedis 来连接到 Redis,Jackson 来操作 JSON 和使用 SLF4J 记录日志。
// Configuration final Config config = new ConfigBuilder().build(); // Add a job to the queue final Job job = new Job("TestAction", new Object[]{ 1, 2.3, true, "test", Arrays.asList("inner", 4.5)}); final Client client = new ClientImpl(config); client.enqueue("foo", job); client.end(); // Add a job to the delayed queue final Job job = new Job("TestAction", new Object[]{ 1, 2.3, true, "test", Arrays.asList("inner", 4.5)}); final long delay = 10; // in seconds final long future = System.currentTimeMillis() + (delay * 1000); // timestamp final Client client = new ClientImpl(config); client.delayedEnqueue("fooDelay", job, future); client.end(); // Start a worker to run jobs from the queue final Worker worker = new WorkerImpl(config, Arrays.asList("foo"), new MapBasedJobFactory(map(entry("TestAction", TestAction.class)))); final Thread workerThread = new Thread(worker); workerThread.start(); // Wait a few secs then shutdown try { Thread.sleep((delay * 1000) + 5000); } catch (Exception e){} // Give ourselves time to process worker.end(true); try { workerThread.join(); } catch (Exception e){ e.printStackTrace(); }