views:

41

answers:

1

Hi all, 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 another 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

A: 

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.

Aaron Digulla
Sorry, Actually I already set the delay only 10 seconds, It doesn't work too, the process is always loop every 10 seconds but publishing state never finished. The code above is my last modification, I scaled up the delay for seeking another possibility.
Mr.K
what a totally ridiculous misplaced, you're right!, I already put to the the run(), it works well.
Mr.K