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

Thread priority  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to start the Test2 Thread after Test1 thread complected ?











|
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole idea of threads is that they are started at (approximately) the same time. Why do you insist on starting the two sequentially? And that has nothing to do with priorities of threads.

Straight sequential programming? Pass thread 2 to the constructor of a class which starts thread 1 in the run() method?
 
Scott Bee
Greenhorn
Posts: 16
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There may be times when the calculations of one thread depend on the completion of another.

Thread.join() gives the programmer the ability to dictate sequential processing. Documentation is here:
https://docs.oracle.com/javase/tutorial/essential/concurrency/join.html

FYI to Kri -- there are several syntax errors in your code. Are your examples essentially intended as pseudocode to give us an idea of what you want to happen?

--Scott
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Join does what you say: delays completion of a thread until after the other thread has completed too. It doesn't delay starting until the other thread has completed.

I am blowed if I can think of a reason why you would wish to delay starting.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!