Re: Help with Thread - Long requests
Re: Help with Thread - Long requests
- Subject: Re: Help with Thread - Long requests
- From: Chuck Hill <email@hidden>
- Date: Tue, 24 Feb 2009 08:50:12 -0800
On Feb 24, 2009, at 2:44 AM, Amedeo Mantica wrote:
I was looking at the LongResponseExample.java in the AjaxExample....
as you can see i the component ther is a subclass called Tast that
extends Thread
and this works great, I can navigate to other webpagrs while task is
running.
So, I have created ( probably badly ) a subclass indide the Session
that extends Thread, it works, but i cannot navigate pages while
running.
Suggestions?
Not without seeing what you did in session. There is NO reason that
this needs to be a static inner class. Most of my runnables are
separate classes.
Chuck
// 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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
--
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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden