• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Thread - Concurrency

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!