• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Thread - Concurrency

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

Problem Statement : I am adding 3 Object Instances of FCS to ArrayList and
executing them in run() of BoomerangServiceTest. FCS in turn extends from Thread which when start, FCS will execute run.

Same thing happens repeatedly after some Interval which is scheduled by Timertask.

Unfortunately, Thread control is not coming back after FCS is executing 3rd time.

Does Thread expires after run() is executed or we need to stop() explicitly

[ added [url=http://faq.javaranch.com/view?UseCodeTags]code tags - Jim ]
[ January 25, 2007: Message edited by: Jim Yingst ]
 
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that the code you've given here wouldn't quite compile; there are little bits and pieces of extra text here and there, and missing methods like getInstance(), and a lot of likely non-fatal mistakes as well (passing 'i' to the FCS constructor in the loop, for example.) It's hard to say precisely what you expect to happen when you're not showing us the whole code.

But one thing you might not know is that you can call start() on a Thread just once. Once a thread has been started, it can never be "re-started"; when it's done, it has to be just thrown out.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nageswar Kakolla:

Does Thread expires after run() is executed or we need to stop() explicitly



Note that in general you should not be calling the stop() method on a thread. The Java API discusses why that method is unsafe and why it should be avoided.

Also, on a side note. You may also want to avoid variable "shadowing" where you have local variables named the same as your member variables. In a small example, it's not too hard to follow, but this can certainly lead to confusion and problems as your code grows.
 
I can't take it! You are too smart for me! Here is the tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic