This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Runnable  RSS feed

 
anita sam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
below is my part of code, there are 2 daemons that i want to run, if i put ******dMap.put(daemonName, tr);
sDaemons.add(daemonName);*************
these 2 line after the start(), only one of my daemon is running can some one help me with it....thanks.


 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused by the scoping of count. Does the first thread increment the count being used to control the loop up in initDaemons()? Give TestRun some other variable to play with and see what happens. If your goal is to have both daemons increment the same variable, read up on the volatile keyword and/or synchronize the method that does the increment on some shared object.

BTW: Threads spawned by the non-daemon main() thread are not daemons by default. You have to setDaemon true before you call start(). Non-daemon threads will stop when the main() exits. Daemon threads will run until they stop on their own.

Let me know if that helps!
 
anita sam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan,
count in the TestRun is a different variable...sorry i did'nt put that in my code. Thanks Stan for your help.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!