当前位置: 首页 > 工具软件 > jesque > 使用案例 >

resque java_jesque

柴宝
2023-12-01

软件简介

jesque 是 Resque 的Java语言实现版。

使用示例:

// 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(); }

 类似资料:

相关阅读

相关文章

相关问答