Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Preempting the main thread  RSS feed

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it possible for the main thread or the intial thread to be preempted while its children are not?
Thanks
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean. To me in order for a thread to be pre-empted the thread must have been running in the first place. Only one thread can run at a time. So if a thread is pre-empted, no other threads are pre-empted at the same time, since no other threads were actually running.
That probably isn't what you meant, so can you rephrase?
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the confussion.
What I meant is something like this:

When I type java A, a main thread is created. When the program reaches line 1, a child thread is created. So now there are two threads, the main and the child.
My question now is can the main thread be swapped-out (that is moved out from the running state) but its child remains running?
Thanks.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the way the JVM deals with threads, it doesn't really care about the parent-child relationship. The JVM just keeps running as long as there are non-daemon threads still running. It starts with one thread, main, starts another thread (call it thread-1), mean ends, but the JVM doesn't care, it just knows that it's still got one (non-daemon) thread running, so it keeps on going until that ends (assuming no other threads are spawned).
Does that answer your question, or did I misunderstand again?
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that answer it Thank you.
I was thinking along the line on how most OS swap programs out.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!