RE: Exception: current thread not owner

2004-10-18 Thread Shapira, Yoav

Hi,

process a request. This request is asynchronous and I have to wait for
the
output before I can continue. When I try to put a wait( 1000 ) line in
my
code I
get the exception that I am not the owner of the current thread. How
can I
set
up a wait so I don't burn CPU in a tight loop?

Yup, you don't own the request processing thread, Tomcat does.  If you
blocked it, other requests couldn't use it.

You'd still have to use a loop (assuming you're not interested in a
design-driven solution like JMS or another event-driven model), but you
can make it less tight by checking every X ms instead of all the time,
and you can do it in a separate thread that you spawn.  Unlike the
server threads, you'd own that thread so you could sleep or wait it as
needed.

Yoav



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Exception: current thread not owner

2004-10-18 Thread Robert Harper


 You'd still have to use a loop (assuming you're not interested in a
 design-driven solution like JMS or another event-driven model), but you
 can make it less tight by checking every X ms instead of all the time,
 and you can do it in a separate thread that you spawn.  Unlike the
 server threads, you'd own that thread so you could sleep or wait it as
 needed.
[Robert Harper] 
I still need to know how I am to wait without burning the CPU while I am waiting
for a response. I would rather not have to have the web page have to keep
checking back for a response.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Exception: current thread not owner

2004-10-18 Thread Filip Hanik - Dev
I still need to know how I am to wait without burning the CPU while I am waiting

sleep() or wait() does wait without burning CPU

Filip
- Original Message - 
From: Robert Harper [EMAIL PROTECTED]
To: 'Tomcat Users List' [EMAIL PROTECTED]
Sent: Monday, October 18, 2004 2:40 PM
Subject: RE: Exception: current thread not owner




 You'd still have to use a loop (assuming you're not interested in a
 design-driven solution like JMS or another event-driven model), but you
 can make it less tight by checking every X ms instead of all the time,
 and you can do it in a separate thread that you spawn.  Unlike the
 server threads, you'd own that thread so you could sleep or wait it as
 needed.
[Robert Harper] 
I still need to know how I am to wait without burning the CPU while I am waiting
for a response. I would rather not have to have the web page have to keep
checking back for a response.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Exception: current thread not owner

2004-10-18 Thread Shapira, Yoav

Hi,

[Robert Harper]
I still need to know how I am to wait without burning the CPU while I
am
waiting
for a response. I would rather not have to have the web page have to
keep
checking back for a response.

It's been a while since I've had to post code on here ;)  Here's a
generic way to spawn a thread and only check on it every X milliseconds,
instead of all the time, so that you don't burn the CPU:

class MyServlet extends HttpServlet {
  ...
  ...doGet(...) {
Thread myThread = new MyThread();
while(! (myThread.isDone())) {
  Thread.currentThread().sleep(5000);
}
myThread = null;

...
  }
}

class MyThread extends Thread() {
  ...
  boolean done = false;

  MyThread() {
...
setDaemon(true);
  }

  run() {
...
done = true;
  }

  boolean isDone() {
return done;
  }
}

That's it.  I omitted accessors and such for brevity, but I hope you get
the point of this approach.  As I said previously, this is still
inferior, both from a cleanliness/maintainability and from a
Spec-compliance point of view, to a design-based solution like JMS.  But
it'll work, so hopefully now I've given enough detail for you.

Yoav




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Exception: current thread not owner

2004-10-18 Thread Robert Harper
 It's been a while since I've had to post code on here ;)  Here's a
 generic way to spawn a thread and only check on it every X milliseconds,
 instead of all the time, so that you don't burn the CPU:
[Robert Harper] 
I know how to create threads. I did not intend for you to treat me like a total
newbie but I guess I am.

I still don't see how I have the servlet check back every so many ms for an
event or a status flag to be set without performing some sleep() or wait()
without burning CPU.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Exception: current thread not owner

2004-10-18 Thread Shapira, Yoav

Hi,

I still don't see how I have the servlet check back every so many ms
for an
event or a status flag to be set without performing some sleep() or
wait()
without burning CPU.

I don't get it.  You don't want the servlet to return until it's done
writing the web page, which means waiting for your async request to
complete.  But you don't want to wait, you don't ant to sleep, and you
don't want to burn CPU.

HTTP is a stateless protocol.  One request = one response, with all the
content.  You can do stuff with JavaScript like posting a request in
progress text and polling for the servlet to complete, but that's
tricky and fragile.

Are you looking for a client-side or server-side solution?  Have you
considered having the servlet use JMS for this, i.e. send a JMS message
and block until its returned?

Have you actually profiled a wait() or sleep() request to see that it
burns CPU?  You might be positively surprised...

Yoav



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Exception: current thread not owner

2004-10-18 Thread Ben Souther

I still don't see how I have the servlet check back every so many ms
for an
event or a status flag to be set without performing some sleep() or
wait()
without burning CPU.

His code wasn't without a sleep() call.










On Mon, 2004-10-18 at 16:02, Robert Harper wrote:
  It's been a while since I've had to post code on here ;)  Here's a
  generic way to spawn a thread and only check on it every X milliseconds,
  instead of all the time, so that you don't burn the CPU:
 [Robert Harper] 
 I know how to create threads. I did not intend for you to treat me like a total
 newbie but I guess I am.
 
 I still don't see how I have the servlet check back every so many ms for an
 event or a status flag to be set without performing some sleep() or wait()
 without burning CPU.
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]