Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

working with two threads!!  RSS feed

 
Sapna Korecherla
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have two threads started off like ...

t1.start();
t2.start();

does this mean that both of them start off simultaneously one after the other at the same time?
and if the thread t2 is a timer of the thread t1, then does the timer thread gives the time taken for thread t1 to run( assuming the code for timer is working fine)?

PLease let me know
Sapna
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very important point - you really cannot make any assumptions about which one starts first.
 
Sapna Korecherla
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why?
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look here:

http://java.sun.com/docs/books/tutorial/essential/threads/index.html

The essential point is that when you're writing multithreaded code, you can *never* (by default) safely make *any* assumptions about "what happens when". If the processing in one thread is dependent on the activities of a different thread, then you must *always* use some kind of explicit synchronization.

'Hope that helps .. PSM
 
Sapna Korecherla
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks PSM !!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!