⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listener.java~1~

📁 封装了SQL、Socket、WAP、MIME等功能的通用组件
💻 JAVA~1~
字号:
/**
 * <p>Title: 即时通信</p>
 * <p>Description: 即时通信服务器</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: 深圳市科皓信息技术有限公司</p>
 * @author 刘学
 * @version 1.0
 */
package com.lazybug.util;

import java.util.ArrayList;

public abstract class Listener implements Runnable
{
    protected Thread thread;
    protected boolean isRunning;
    protected boolean isBusy = true;      //是否忙
    protected long calculagraph;      //计时器
    protected String remark;
    private static ArrayList threadQuene = new ArrayList();
    private static int thread_count;
    public Listener()
    {
        this.isRunning = false;
    }

    public static void printThreadStatus()
    {
        for(int i = 0; i < threadQuene.size(); i++ )
        {
            String str = ((Listener)threadQuene.get(i)).status();
            if( str != null ) System.out.println(str);
        }
    }

    public void start()
    {
        thread = new Thread(this);
        this.isRunning = true;
        thread.start();
        synchronized( threadQuene )
        {
            threadQuene.add( this );
        }
    }

    /**
     * 强制性中断
     */
    public void halt()
    {
        if( this.thread != null && this.isRunning)
        {
            Thread remover = this.thread;
            remover.interrupt();
            this.thread = null;
            this.isRunning = false;
            synchronized( threadQuene )
            {
                threadQuene.remove( this );
            }
        }
    }

    /**
     * 发出停止的指令
     */
    public void stop()
    {
        this.isRunning = false;
        synchronized( threadQuene )
        {
            threadQuene.remove( this );
        }
    }

    public String status()
    {
        if( remark == null ) return null;
        return remark+":"+(isRunning?(this.isBusy?"忙["+this.calculagraph+"]":"空闲"):"线程已关闭");
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -