本文整理匯總了Java中org.snmp4j.util.WorkerTask類的典型用法代碼示例。如果您正苦於以下問題:Java WorkerTask類的具體用法?Java WorkerTask怎麽用?Java WorkerTask使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WorkerTask類屬於org.snmp4j.util包,在下文中一共展示了WorkerTask類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testMultipleTasks
import org.snmp4j.util.WorkerTask; //導入依賴的package包/類
@Test
public void testMultipleTasks() throws Exception {
final int taskCount = 50;
final MockWorkerTask[] delegates = new MockWorkerTask[taskCount];
for (int i = 0; i < taskCount; i++) {
delegates[i] = new MockWorkerTask();
final WorkerTask task = factory.createWorkerThread("task " + i,
delegates[i], false);
task.run();
}
final long start = System.currentTimeMillis();
boolean done = false;
while (!done && System.currentTimeMillis() - start < taskCount * 100) {
done = true;
for (int i = 0; i < taskCount; i++) {
done = done && delegates[i].awaitReady(10);
}
}
assertThat(done, is(true));
}
示例2: createWorkerThread
import org.snmp4j.util.WorkerTask; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public WorkerTask createWorkerThread(String name, WorkerTask task,
boolean daemon) {
Thread thread = delegate.newThread(task);
thread.setName(name);
thread.setDaemon(daemon);
return new ThreadWorkerTask(thread);
}
示例3: testSingleTask
import org.snmp4j.util.WorkerTask; //導入依賴的package包/類
@Test
public void testSingleTask() throws Exception {
final MockWorkerTask delegate = new MockWorkerTask();
final WorkerTask task = factory.createWorkerThread("some name",
delegate, false);
task.run();
assertThat(delegate.awaitReady(1000), is(true));
}
示例4: execute
import org.snmp4j.util.WorkerTask; //導入依賴的package包/類
public void execute(final WorkerTask task) {
T context = contextHolder.remove(Thread.currentThread());
executer.submit(
new ContextfulWorkerTask(task, context)
);
}
示例5: tryToExecute
import org.snmp4j.util.WorkerTask; //導入依賴的package包/類
public boolean tryToExecute(WorkerTask task) {
execute(task);
return true;
}
示例6: ContextfulWorkerTask
import org.snmp4j.util.WorkerTask; //導入依賴的package包/類
private ContextfulWorkerTask(WorkerTask task, T context) {
this.task = task;
this.context = context;
}