• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help with Thread - Long requests
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with Thread - Long requests


  • Subject: Re: Help with Thread - Long requests
  • From: Chuck Hill <email@hidden>
  • Date: Tue, 24 Feb 2009 09:10:30 -0800


On Feb 24, 2009, at 8:59 AM, Amedeo Mantica wrote:

actually I did'n touch the Session

You said, "I have created a subclass indide the Session that extends Thread". How did you start that?


Chuck


On 24/feb/09, at 17:50, Chuck Hill wrote:


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











-- 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
References: 
 >Help with Thread - Long requests (From: Amedeo Mantica <email@hidden>)
 >Re: Help with Thread - Long requests (From: Chuck Hill <email@hidden>)
 >Re: Help with Thread - Long requests (From: Amedeo Mantica <email@hidden>)
 >Re: Help with Thread - Long requests (From: Chuck Hill <email@hidden>)
 >Re: Help with Thread - Long requests (From: Mike Schrag <email@hidden>)
 >Re: Help with Thread - Long requests (From: Chuck Hill <email@hidden>)
 >Re: Help with Thread - Long requests (From: Amedeo Mantica <email@hidden>)
 >Re: Help with Thread - Long requests (From: Chuck Hill <email@hidden>)
 >Re: Help with Thread - Long requests (From: Amedeo Mantica <email@hidden>)

  • Prev by Date: Re: Chuck, you branching out?
  • Next by Date: Re: oops, EditingContext disposed?
  • Previous by thread: Re: Help with Thread - Long requests
  • Next by thread: Re: Help with Thread - Long requests
  • Index(es):
    • Date
    • Thread