Mercurial > hg > Database > Alice
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 |
rev | line source |
---|---|
6 | 1 package alice.codesegment; |
2 | |
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 | 6 |
7 public class CodeSegmentManager { | |
8 private static CodeSegmentManager instance = new CodeSegmentManager(); | |
8 | 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 | 15 |
16 private CodeSegmentManager() { | |
8 | 17 Runnable prepareThread = new Runnable() { |
6 | 18 |
19 @Override | |
20 public void run() { | |
21 while (true) { | |
22 try { | |
8 | 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 | 25 } catch (InterruptedException e) { |
26 e.printStackTrace(); | |
27 } | |
28 } | |
29 } | |
8 | 30 |
6 | 31 }; |
20 | 32 new Thread(prepareThread, "CodeSegmentManager").start(); |
6 | 33 } |
34 | |
35 public void create(CodeSegment cs) { | |
36 } | |
37 | |
38 public static CodeSegmentManager get() { | |
39 return instance; | |
40 } | |
41 } |