本文整理匯總了Java中org.openide.util.RequestProcessor.submit方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestProcessor.submit方法的具體用法?Java RequestProcessor.submit怎麽用?Java RequestProcessor.submit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.util.RequestProcessor
的用法示例。
在下文中一共展示了RequestProcessor.submit方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/**
* Starts executable and returns immediately.
* @param execEnv - target execution environment
* @param rp - RequestProcessor that is used for running the task.
* Could be NULL. In this case default (private) processor is used.
* Note that default (private) processor has throughput == 1
* @param postExecutor - once process is done, passed postExecutor will be
* notified. Call of postExecutor's method is performed in the same thread
* as invocation of the executable (i.e. in rp (see above)).
* @param executable - full path to executable to run.
* @param args - list of arguments to pass to executable
* @return Future ExitStatus
*/
public static Future<ExitStatus> execute(final ExecutionEnvironment execEnv, final RequestProcessor rp, final PostExecutor postExecutor, final String executable, final String... args) {
final RequestProcessor processor = (rp == null) ? RP : rp;
return processor.submit(new Callable<ExitStatus>() {
@Override
public ExitStatus call() throws Exception {
ExitStatus status = null;
String error = null;
try {
status = execute(execEnv, executable, args);
} catch (Throwable t) {
error = t.getMessage();
} finally {
if (postExecutor != null) {
postExecutor.processFinished(error == null ? status : new ExitStatus(1, null, Arrays.asList(error.split("\n")))); // NOI18N
}
}
return status;
}
});
}
示例2: testCancelDoesNotInterruptIfNotPassedToFutureDotCancel
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
public void testCancelDoesNotInterruptIfNotPassedToFutureDotCancel() throws Exception {
RequestProcessor rp = new RequestProcessor ("X", 3, false, true);
final CountDownLatch releaseForRun = new CountDownLatch(1);
final CountDownLatch enterLatch = new CountDownLatch(1);
final CountDownLatch exitLatch = new CountDownLatch(1);
class R implements Runnable {
volatile boolean interrupted;
@Override
public void run() {
enterLatch.countDown();
try {
releaseForRun.await();
} catch (InterruptedException ex) {
interrupted = true;
}
interrupted |= Thread.interrupted();
exitLatch.countDown();
}
}
R r = new R();
Future<?> f = rp.submit(r);
enterLatch.await();
f.cancel(false);
assertTrue (f.isCancelled());
assertFalse (r.interrupted);
}
示例3: testSubmittedTasksExecutedBeforeShutdown
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
public void testSubmittedTasksExecutedBeforeShutdown() throws InterruptedException {
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch executedLatch = new CountDownLatch(2);
Runnable dummyRunnable = new Runnable() {
@Override
public void run() {
try {
startLatch.await();
Thread.sleep(100);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} finally {
executedLatch.countDown();
}
}
};
RequestProcessor rp = new RequestProcessor("X", 1);
rp.submit(dummyRunnable);
rp.submit(dummyRunnable);
rp.shutdown();
startLatch.countDown();
assertTrue("Submitted tasks not executed", executedLatch.await(5, TimeUnit.SECONDS));
}
示例4: testCancelFutureInterruptsThreadEvenIfRequestProcessorForbidsIt
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
public void testCancelFutureInterruptsThreadEvenIfRequestProcessorForbidsIt() throws Exception {
RequestProcessor rp = new RequestProcessor ("X", 3, false, true);
final CountDownLatch releaseForRun = new CountDownLatch(1);
final CountDownLatch enterLatch = new CountDownLatch(1);
final CountDownLatch exitLatch = new CountDownLatch(1);
class R implements Runnable {
volatile boolean interrupted;
@Override
public void run() {
enterLatch.countDown();
try {
releaseForRun.await();
} catch (InterruptedException ex) {
interrupted = true;
}
interrupted |= Thread.interrupted();
exitLatch.countDown();
}
}
R r = new R();
Future<?> f = rp.submit(r);
enterLatch.await();
f.cancel(true);
assertTrue (f.isCancelled());
exitLatch.await();
assertTrue (r.interrupted);
}
示例5: testAwaitingTasksReturnedOnShutdownNow
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
public void testAwaitingTasksReturnedOnShutdownNow() throws InterruptedException {
final CountDownLatch startupLatch = new CountDownLatch(2);
final CountDownLatch blockingLatch = new CountDownLatch(1);
Runnable blockingRunnable = new Runnable() {
@Override
public void run() {
try {
startupLatch.countDown();
startupLatch.await();
blockingLatch.await();
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
};
Runnable awaitingRunnable = new Runnable() {
@Override
public void run() {
// noop
}
};
RequestProcessor rp = new RequestProcessor("X", 1);
rp.submit(blockingRunnable);
startupLatch.countDown();
startupLatch.await();
rp.submit(awaitingRunnable);
Set<Runnable> awaiting = new HashSet<Runnable>(rp.shutdownNow());
assertTrue("Awaiting task not returned on shutdownNow()", awaiting.contains(awaitingRunnable));
assertFalse("Running task returned on shutdownNow()", awaiting.contains(blockingRunnable));
}
示例6: testListeners
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
@ForAllEnvironments(section = "remote.platforms")
public void testListeners() throws Exception {
int count = 5;
RequestProcessor rp = new RequestProcessor("testListeners", 50);
final CountDownLatch done = new CountDownLatch(count * 4);
final CountDownLatch start = new CountDownLatch(1);
for (int i = 0; i < count * 4; i++) {
final int x = i;
rp.submit(new Runnable() {
@Override
public void run() {
try {
start.await();
switch (x % 4) {
case 0:
doTestListeners(getTestExecutionEnvironment(), true, true);
break;
case 1:
doTestListeners(getTestExecutionEnvironment(), true, false);
break;
case 2:
doTestListeners(getTestExecutionEnvironment(), false, true);
break;
case 3:
doTestListeners(getTestExecutionEnvironment(), false, false);
break;
}
} catch (Throwable ex) {
Exceptions.printStackTrace(ex);
} finally {
done.countDown();
}
}
});
}
start.countDown();
done.await();
}