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

📄 threadcontrol.java

📁 j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件
💻 JAVA
字号:
package com.jmobilecore.thread;

public class ThreadControl {

    /**
     * The current thread
     */
    public AdvThread thread;

    public ThreadControl(Runnable task) {
        setTask(task, 0);
    }

    public ThreadControl(Runnable task, int frequency) {
        setTask(task, frequency);
    }

    /**
     * Sets the current task and frequency of the task execution
     * @param task the new <code>Runnable</code> task
     * @param frequency the frequency of the task execution
     * @return <code>true</code> if setup is successful, <code>false</code> otherwise
     */
    protected boolean setTask(Runnable task, int frequency) {

        if (frequency<0) return false;
        thread = new AdvThread(task, frequency);
        if (thread != null) {
            thread.start();
            return true;
        }
        return false;
    }

    /**
     * Stops the current thread
     */
    public boolean stop() {
       return reset(0, 0);
    }

    /**
     * Resets frecuency and delay for the current thread
     * @param frequency the frequency of the task execution
     * @param delay the delay before the first task execution
     * @return <code>true</code> if reset is successful, <code>false</code> otherwise
     */
    public boolean reset(int frequency, int delay) {

        if (thread != null && thread.isAlive() ) {
            return thread.setFrequency(frequency, delay);
        }
        return false;
    }

    /**
     * Terminates the current thread
     * @return <code>true</code> if termination is done, <code>false</code> otherwise
     */
    public boolean terminate() {
        if (thread != null && thread.isAlive() ) {
            return thread.terminate();
        }
        return false;
    }

    /**
     * Default destructor. Helps VM to perform garbage collection
     */
    public void destructor() {
        if ( !terminate() ) return;
        thread = null;
    }
}

⌨️ 快捷键说明

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