package com.ctrip.zeus.task;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author:xingchaowang
 * @date: 12/7/2015.
 */
public abstract class AbstractTask implements Task {
    @Resource
    private TaskManager taskManager2;

    @PostConstruct
    private void init() {
        taskManager2.add(this);
        start();
    }

    public abstract void start();

    @Override
    public String getName() {
        return getClass().getSimpleName();
    }

    @Override
    public long getInterval() {
        return 60000;
    }

    public abstract void run() throws Exception;

    @Override
    public void shutDown() {
        stop();
        taskManager2.remove(this);
        taskManager2 = null;
    }

    public abstract void stop();
}

package com.ctrip.zeus.task;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author:xingchaowang
 * @date: 12/7/2015.
 */
public abstract class AbstractTask implements Task {
    @Resource
    private TaskManager taskManager2;

    @PostConstruct
    private void init() {
        start();
        taskManager2.add(this);
    }

    public abstract void start();

    @Override
    public String getName() {
        return getClass().getSimpleName();
    }

    @Override
    public long getInterval() {
        return 60000;
    }

    public abstract void run() throws Exception;

    @Override
    public void shutDown() {
        stop();
        taskManager2.remove(this);
        taskManager2 = null;
    }

    public abstract void stop();
}

switch start and add process