- /**
- * Created by IntelliJ IDEA.
- * User: fengzhizi
- * Date: 2006-2-23
- * Time: 16:41:45
- * To change this template use File | Settings | File Templates.
- */
- public class TimeSlicer extends Thread {
- private long timeslice;
- public TimeSlicer (long milliseconds,int priority)
- {
- this.timeslice=milliseconds;
- this.setPriority(priority);
- //如果这是所剩的最后一个线程,这不应到阻止VM退出
- this.setDaemon(true);
- }
- //使用最高优先级
- public TimeSlicer(long milliseconds)
- {
- this(milliseconds,10);
- }
- //使用最高优先级和100ms 时间片
- public TimeSlicer()
- {
- this(100,10);
- }
- public void run()
- {
- while(true)
- {
- try
- {
- Thread.sleep(timeslice);
- }
- catch(InterruptedException ex)
- {}
- }
- }
- }
复制代码 |