annotate src/alice/codesegment/CodeSegmentManager.java @ 21:145667a554ad

run CodeSegment with ThreadPoolExecutor
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Sun, 15 Jan 2012 19:02:01 +0900
parents 0bb03861b5cd
children 3155337e754e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
1 package alice.codesegment;
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
2
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
3 import java.util.concurrent.LinkedBlockingQueue;
21
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
4 import java.util.concurrent.ThreadPoolExecutor;
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
5 import java.util.concurrent.TimeUnit;
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
7 public class CodeSegmentManager {
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
8 private static CodeSegmentManager instance = new CodeSegmentManager();
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
9 public LinkedBlockingQueue<CodeSegment> readyQueue = new LinkedBlockingQueue<CodeSegment>();
21
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
10 ThreadPoolExecutor codeSegmentExecutor = new ThreadPoolExecutor(1,
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
11 Runtime.getRuntime().availableProcessors(),
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
12 Integer.MAX_VALUE,
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
13 TimeUnit.SECONDS,
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
14 new LinkedBlockingQueue<Runnable>());
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
15
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
16 private CodeSegmentManager() {
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
17 Runnable prepareThread = new Runnable() {
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
18
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
19 @Override
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
20 public void run() {
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
21 while (true) {
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
22 try {
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
23 CodeSegment cs = readyQueue.take();
21
145667a554ad run CodeSegment with ThreadPoolExecutor
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 20
diff changeset
24 codeSegmentExecutor.execute(cs);
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
25 } catch (InterruptedException e) {
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
26 e.printStackTrace();
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
27 }
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
28 }
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
29 }
8
78b415d019de Local DS and CS work! maybe...
one
parents: 7
diff changeset
30
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
31 };
20
0bb03861b5cd set name to Thread
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
32 new Thread(prepareThread, "CodeSegmentManager").start();
6
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
33 }
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
34
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
35 public void create(CodeSegment cs) {
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
36 }
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
37
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
38 public static CodeSegmentManager get() {
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
39 return instance;
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
40 }
c78a1cc2cd8f implements Reply
one
parents:
diff changeset
41 }