• Post Reply Bookmark Topic Watch Topic
  • New Topic

new Thread reuses current thread!?  RSS feed

 
Robert John
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

my problem: I'm developing some application for the sap enterprise portal. this application is supposed to call multiple threads to retrieve some information. now after some time measurement I found out that the whole thing always reuses one single thread.

like this:

this call of run() stops the current code from executing, it's waiting until the Thread is stopped then finally goes on. so "new Thread()" does open a new class but not a thread

the thread class is defined like this:


I have no idea how this can happen, I tried it outside of the sap portal and it seems to work, I have no chance to do it as a portal component up to now.

any ideas? Thanks in advance!
Salty
[ December 07, 2006: Message edited by: Robert John ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch!

And welcome to the very large club of those who have made exactly that mistake. You need to call start() on the Thread instead of run(). start() does all the magic to create a new thread and eventually calls run() on the new thread. When you call run() directly, you bypass the magic and run it in the current thread, just as you observed.


Hmm, reading again you said this works outside the portal? Maybe the run() was just a typo? If so we may need to think some more.
[ December 07, 2006: Message edited by: Stan James ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

You never call "run()" on a Thread yourself. Instead you call "start()", which goes off and creates a separate parallel thread of execution, and calls run() from there.

Multithreaded program is easy, but complex. It would be really worth your while to go off and read this introductory tutorial on threads before continuing; it will save you a lot of headaches.
 
Robert John
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
some swearwords come to mind... and words of thanks to my 2 helpers - thanks a lot! it works!

I already start to feel at home here! never did any threading, developed for the most part ejb's the last 2 years... and now some sort of webcrawler... pfhh - again, thanks!
Robert
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!