// Generated by the WOLips Templateengine Plug-in at 07.08.2006
16:32:09
import org.apache.log4j.Logger;
import com.webobjects.appserver.WOActionResults;
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WOContext;
public class LongResponseExample extends WOComponent {
static Logger log = Logger.getLogger(LongResponseExample.class);
public static class Task extends Thread {
int stage = 0;
String status = "Idle";
public void run() {
try {
setStatus("Starting up");
sleep(2000);
while (stage < 20) {
sleep(1000);
stage++;
setStatus("Currently at stage: " + stage);
}
setStatus("Finished");
}
catch (InterruptedException e) {
status = "Interrupted";
}
}
private void setStatus(String value) {
status = value;
log.info(status);
}
public String getStatus() {
return status;
}
}
public Task task;
public LongResponseExample(WOContext context) {
super(context);
}
public long test() {
return System.currentTimeMillis();
}
public WOComponent startTask() {
task = new Task();
task.start();
return null;
}
public WOActionResults stopTask() {
task.interrupt();
return null;
}
}
On 23/feb/09, at 22:36, Chuck Hill wrote:
On Feb 23, 2009, at 1:32 PM, Mike Schrag wrote:
Actually I'm able to do it only if i create a subclass that
extends Thread in the component that will start it.
I don't understand why that is necessary. What happens if
you don't do this?
random pet peeve btw ... you should never extend Thread.
you're not a thread, you're a thing a thread runs ... you
should implement Runnable.
Truth. And a mistake I have made several times in the past.
Chuck
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase
their overall knowledge of WebObjects or who are trying to
solve specific problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobjects-
email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden