Created
February 8, 2012 16:08
-
-
Save ryoasai/1770759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()が終了。"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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