public static void main(String[] argv) throws IOException { Task t; boolean home = argv.length > 0 && argv[0].equals("test"); InputStream inputStream; OutputStream outputStream; if (home) { inputStream = new FileInputStream(Task.filename + ".in"); outputStream = new FileOutputStream(Task.filename + ".out"); } else { switch (Task.read) { case 0: inputStream = new FileInputStream(Task.filename + ".in"); outputStream = new FileOutputStream(Task.filename + ".out"); break; case 1: inputStream = new FileInputStream("input.txt"); outputStream = new FileOutputStream("output.txt"); break; default: inputStream = System.in; outputStream = System.out; break; } } InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream, home); if (home) do { long time = System.currentTimeMillis(); t = new Task(); t.in = in; t.out = out; t.run(); out.writeln(); out.writeln("=====Time:" + (System.currentTimeMillis() - time)); out.flush(); } while (in.toNextTest()); else { t = new Task(); t.in = in; t.out = out; t.run(); } out.close(); }
// WARN Watch this code, see if we can do better, maybe leverage @UnitOfWorkRetry @Override public void run() { System.out.println("Running Schedule"); Usecase usecase = UsecaseBuilder.newUsecase("ScheduleRunner"); UnitOfWork uow = module.newUnitOfWork(usecase); try { Schedule schedule = uow.get(Schedule.class, this.schedule.scheduleIdentity); Task task = schedule.task().get(); schedule = uow.get(Schedule.class, this.schedule.scheduleIdentity); try { schedule.taskStarting(); task.run(); schedule.taskCompletedSuccessfully(); } catch (RuntimeException ex) { schedule.taskCompletedWithException(ex); } schedulerMixin.dispatchForExecution(schedule); uow.complete(); } catch (UnitOfWorkCompletionException ex) { } finally { // What should we do if we can't manage the Running flag?? if (uow.isOpen()) { uow.discard(); } } }
@Override protected IStatus run(final IProgressMonitor monitor) { while (true) { Task task; synchronized (fTasksLock) { final IModelElement element = (!fTaskQueue.isEmpty()) ? fTaskQueue.removeFirst() : null; if (element == null || fStop) { fWorking = false; return Status.OK_STATUS; } fWorking = true; task = fTaskDetail.remove(element); } try { task.run(); } catch (final Throwable e) { LTKCorePlugin.log( new Status( IStatus.ERROR, LTK.PLUGIN_ID, -1, "An error occurred when firing model event for " + fModelManager.getModelTypeId() + ".", //$NON-NLS-1$ e)); } } }
public void runTask(Class<? extends Task> clazz) { try { Task task = clazz.newInstance(); task.run(this); } catch (ReflectiveOperationException e) { handleException(e); } }
@Override public void run() { int i = 0; while (i < 50) { Task task = new Task(i); task.run(); i++; } }
@Override public void run() { while (!queue.isEmpty()) { try { Task t = queue.take(); t.run(); } catch (InterruptedException e) { e.printStackTrace(); } } }
<T> void run(Task<T> task) { task.run(inject(typeOf(task))); }