CVS update: JGroups/src/org/jgroups/util HashedTimingWheel.java
"Bela Ban" <[email protected]>
| Newsgroups | gmane.comp.java.javagroups.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: belaban
Date: 10/08/05 06:48:19
Modified: src/org/jgroups/util HashedTimingWheel.java
Log:
made wheel_size and tick_time configurable
Revision Changes Path
1.3 +19 -12 JGroups/src/org/jgroups/util/HashedTimingWheel.java
Index: HashedTimingWheel.java
===================================================================
RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/util/HashedTimingWheel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HashedTimingWheel.java 4 Aug 2010 16:03:32 -0000 1.2
+++ HashedTimingWheel.java 5 Aug 2010 06:48:19 -0000 1.3
@@ -21,7 +21,7 @@
* [1] http://www.cse.wustl.edu/~cdgill/courses/cs6874/TimingWheels.ppt
*
* @author Bela Ban
- * @version $Id: HashedTimingWheel.java,v 1.2 2010/08/04 16:03:32 belaban Exp $
+ * @version $Id: HashedTimingWheel.java,v 1.3 2010/08/05 06:48:19 belaban Exp $
*/
@Experimental @Unsupported
public class HashedTimingWheel implements TimeScheduler, Runnable {
@@ -39,11 +39,11 @@
protected ThreadFactory timer_thread_factory=null;
- protected static final int WHEEL_SIZE=200; // number of ticks on the timing wheel
+ protected int wheel_size=200; // number of ticks on the timing wheel
- protected static final long TICK_TIME=50L; // number of milliseconds a tick has
+ protected long tick_time=50L; // number of milliseconds a tick has
- protected static final long ROTATION_TIME=WHEEL_SIZE * TICK_TIME; // time for 1 lap
+ protected final long ROTATION_TIME;// time for 1 lap
protected final List<MyTask>[] wheel;
@@ -55,7 +55,8 @@
*/
@SuppressWarnings("unchecked")
public HashedTimingWheel() {
- wheel=new List[WHEEL_SIZE];
+ ROTATION_TIME=wheel_size * tick_time;
+ wheel=new List[wheel_size];
pool=new ThreadManagerThreadPoolExecutor(4, 10,
5000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(5000),
Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
@@ -64,8 +65,12 @@
@SuppressWarnings("unchecked")
- public HashedTimingWheel(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, int max_queue_size) {
- wheel=new List[WHEEL_SIZE];
+ public HashedTimingWheel(ThreadFactory factory, int min_threads, int max_threads, long keep_alive_time, int max_queue_size,
+ int wheel_size, long tick_time) {
+ this.wheel_size=wheel_size;
+ this.tick_time=tick_time;
+ ROTATION_TIME=wheel_size * tick_time;
+ wheel=new List[this.wheel_size];
timer_thread_factory=factory;
pool=new ThreadManagerThreadPoolExecutor(min_threads, max_threads,keep_alive_time, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(max_queue_size),
@@ -73,9 +78,11 @@
init();
}
+
@SuppressWarnings("unchecked")
public HashedTimingWheel(int corePoolSize) {
- wheel=(List<MyTask>[])new List[WHEEL_SIZE];
+ ROTATION_TIME=wheel_size * tick_time;
+ wheel=(List<MyTask>[])new List[wheel_size];
pool=new ThreadManagerThreadPoolExecutor(corePoolSize, corePoolSize * 2,
5000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(5000),
Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
@@ -166,8 +173,8 @@
lock.lock();
try {
- int num_ticks=(int)Math.max(1, ((time % ROTATION_TIME) / TICK_TIME));
- int position=(wheel_position + num_ticks) % WHEEL_SIZE;
+ int num_ticks=(int)Math.max(1, ((time % ROTATION_TIME) / tick_time));
+ int position=(wheel_position + num_ticks) % wheel_size;
int rounds=(int)(time / ROTATION_TIME);
List<MyTask> list=wheel[position];
retval=new MyTask(work, rounds);
@@ -288,7 +295,7 @@
while(running) {
try {
_run();
- next_time=base_time + (++cnt * TICK_TIME);
+ next_time=base_time + (++cnt * tick_time);
sleep_time=Math.max(0, next_time - System.currentTimeMillis());
Util.sleep(sleep_time);
}
@@ -302,7 +309,7 @@
protected void _run() {
lock.lock();
try {
- wheel_position=(wheel_position +1) % WHEEL_SIZE;
+ wheel_position=(wheel_position +1) % wheel_size;
List<MyTask> list=wheel[wheel_position];
if(list.isEmpty())
return;
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm