0
我使用Spring框架和oracle weblogic 10.3作爲容器。 我用workmanager來管理我的線程,我已經做了一個由workmanager管理的線程。幸運的是,spring提供了使用workmanager的委託類,所以我只需要將它放在applicationContext.xml上。使用thread.sleep或延遲的工作管理器不起作用
但是當我把「while」和TimeUnit睡眠的過程放在期望的延遲時間上時,部署過程從未完成。看起來部署過程從不會從while循環跳出來完成部署。
爲什麼?因爲我知道使用典型的線程,所以沒有像這樣的問題。我是否應該使用另一種策略使其始終循環並延遲。
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"));
}
}
真的在此先感謝。 問候,
卡利爾
對不起,實際上我已經設置了延遲時間只有10秒,它也不起作用,這個過程總是每10秒循環一次,但發佈狀態永遠不會結束。上面的代碼是我最後一次修改,我放慢了尋求另一種可能性的延遲。 – 2010-05-26 09:24:43
什麼是完全荒謬的錯位,你是對的!,我已經把它運行(),它運作良好。 – 2010-05-27 09:27:02