com.beetle.framework.appsrv
类 AppRunnable

java.lang.Object
  继承者 com.beetle.framework.appsrv.AppRunnable
所有已实现的接口:
java.lang.Runnable
直接已知子类:
AppThreadImp, AppThreadMonitor

public abstract class AppRunnable
extends java.lang.Object
implements java.lang.Runnable

Title: FrameWork

Description: 线程接口封装类

AppRunnable有两个基本属性,theadName线程名称,是这个线程的标识。maxIdle最大空闲时间,单位为秒, 如果线程超过这个最大空闲时间还是处于阻塞状态的话,监控线程回自动停止这个线程,并重新拉起此线程。这个模型的基本运行流程为:
(1),设置最大空闲时间,创建一个线程对象。
(2),调用startNow()方法启动线程,自动调用run()方法完成业务逻辑。
(3),线程运行期间,AppThreadMonitor检查线程阻塞情况,判别是否线程已经停止或超出最大空闲时间。
(4),调用stopNow()方法结束线程的执行,结束前,触发stopEvent()事件。

此类作为一个线程框架抽象的基础类,除非特殊需求,否则不推荐直接继承使用, 建议使用AppThreadImp抽象类

Copyright: Copyright (c) 2003

Company: 甲壳虫软件

版本:
1.0
作者:
余浩东

构造方法摘要
AppRunnable()
           
AppRunnable(int MaixIdle)
          AppRunnable
AppRunnable(java.lang.String threadName)
          AppRunnable
AppRunnable(java.lang.String threadName, int MaixIdle)
          AppRunnable
 
方法摘要
 long getLastTime()
          获取此线程最近一次工作时间
 java.lang.String getName()
          返回线程的名称
 long getStartTime()
          获取线程启动时间(固定)
protected  boolean getStopFlag()
          返回当前结束标记状态
 java.lang.Thread getThread()
          返回当前线程对象
 void interrupt()
          中断线程
 boolean isStoped()
          检测当前线程是否已经结束 若run方法调用isStopped来作为检查一个循环接受标记, 要在run方法体内显性调用resetIdleTime方法来每次复位时间
 void resetIdleTime()
          重置空闲时间,重置后通过getIdleTime()获取的空闲时间为0
abstract  void run()
          线程运行主方法
 void sleep(int iTime)
          线程休眠
 boolean startAsDaemon()
          作为守护线程来启动 多次启动一个线程是非法的。
 boolean startNow()
          启动线程 多次启动一个线程是非法的。
 void stopBrutally()
          粗暴地停止此线程 终止之前先调用stopNow
protected  void stopEvent()
          调用stopNow触发的事件
 void stopNow()
          停止线程
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

AppRunnable

public AppRunnable()

AppRunnable

public AppRunnable(int MaixIdle)
AppRunnable

参数:
MaixIdle - 最大空闲时间,单位为秒

AppRunnable

public AppRunnable(java.lang.String threadName)
AppRunnable

参数:
threadName - 线程名称

AppRunnable

public AppRunnable(java.lang.String threadName,
                   int MaixIdle)
AppRunnable

参数:
threadName - 线程名称
MaixIdle - 最大空闲时间,单位为秒
方法详细信息

getStartTime

public long getStartTime()
获取线程启动时间(固定)


getLastTime

public long getLastTime()
获取此线程最近一次工作时间


getName

public java.lang.String getName()
返回线程的名称

返回:
String

isStoped

public boolean isStoped()
检测当前线程是否已经结束 若run方法调用isStopped来作为检查一个循环接受标记, 要在run方法体内显性调用resetIdleTime方法来每次复位时间

返回:
返回true为已经结束

startNow

public boolean startNow()
启动线程 多次启动一个线程是非法的。特别是当线程已经结束执行后,不能再重新启动。

返回:
成功返回true

startAsDaemon

public boolean startAsDaemon()
作为守护线程来启动 多次启动一个线程是非法的。特别是当线程已经结束执行后,不能再重新启动。

返回:

resetIdleTime

public void resetIdleTime()
重置空闲时间,重置后通过getIdleTime()获取的空闲时间为0


stopEvent

protected void stopEvent()
调用stopNow触发的事件


stopNow

public void stopNow()
停止线程


sleep

public void sleep(int iTime)
线程休眠

参数:
iTime - 休眠时间,单位为毫秒

getThread

public java.lang.Thread getThread()
返回当前线程对象

返回:
Thread

getStopFlag

protected boolean getStopFlag()
返回当前结束标记状态

返回:
boolean

stopBrutally

public void stopBrutally()
粗暴地停止此线程 终止之前先调用stopNow


interrupt

public void interrupt()
中断线程


run

public abstract void run()
线程运行主方法

指定者:
接口 java.lang.Runnable 中的 run