Skip to content

Instantly share code, notes, and snippets.

@ryoasai
Created February 8, 2012 16:08
Show Gist options
  • Save ryoasai/1770759 to your computer and use it in GitHub Desktop.
Save ryoasai/1770759 to your computer and use it in GitHub Desktop.
package seqtest;
//メイン処理。
public class Main {
private static final int TASK_COUNT = 1000000;
public static void main(String[] argv) {
// 非同期タスクたちを順番に実行させる。
SequentialAsyncTask[] tasks = new SequentialAsyncTask[TASK_COUNT];
for (int i = 0; i < TASK_COUNT; i++) {
tasks[i] = new MyTask(i);
}
new AsyncTasksRunner(tasks).begin();
System.out.println("main()が終了。");
}
}
package seqtest;
public class MyTask extends SequentialAsyncTask {
private volatile boolean executed;
private int id;
public MyTask(int id) {
this.id = id;
}
@Override
public boolean exec() {
if (executed) throw new IllegalStateException();
System.out.printf("%sでMyTask[%d]を実行中\n", Thread.currentThread().getName(), id);
int sum = 0;
for (int i=0; i < 100; i++) {
sum += i;
}
executed = true;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment