开发者

Work manager using thread.sleep or delay doesn't work

I used Spring framework and oracle weblogic 10.3 as a container. I used workmanager for manage my thread, I already made one thread that managed by workmanager. Fortunately spring provide the delegation class for using workmanager, so I just need to put it on applicationContext.xml.

But when I put the "while" and TimeUnit for sleep the process on desired delayed time, the deployment process never finished. It seems the deployment process never jump out from while loop for finishing the deployment.

Why?, As I know using typical thread, there is no issue like this. Should I use anoth开发者_StackOverflow社区er strategy for make it always loop and delay.

import java.util.concurrent.TimeUnit;

import org.springframework.core.task.TaskExecutor;

public class TaskExecutorSample{
    Boolean shutdown = Boolean.FALSE;
    int delay = 8000;
    TimeUnit unit = TimeUnit.SECONDS;

    private class MessageGenerator implements Runnable {
        private String message;
        public MessageGenerator(String message){
            this.message = message;
        }

        @Override
        public void run() {
            System.out.println(message);
        }
    }


    private TaskExecutor taskExecutor;
    public TaskExecutorSample(TaskExecutor taskExecutor){
        this.taskExecutor = taskExecutor;
        try {
            while (shutdown.equals(Boolean.FALSE)){
                this.printMessage();
                unit.sleep(delay);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public void printMessage() {
        taskExecutor.execute(new MessageGenerator("Print this Messages"));
    }
}

Really thanks in advance. Regards,

Kahlil


Well, the thread will wait for a bit more than 2h. Did you really wait that long for the deployment to finish?

[EDIT] You're probably doing the wait in the wrong place: You should wait in the run() method of the thread, not the constructor of the class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜