• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads not closing  RSS feed

 
Tapan Agarwal
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a piece of code that creates 10 threads(Thread ClassName-MyThread).
When each threads completes I am incrementing the value of a static variable in the MainClass(which creates the Threads).
When this static variable reaches 10..I am calling a method which closes all the connection objects created.
But somehow this method is never called and the code never terminates.


It was working fine in Java 6...
I have started facing this issue when I moved to java 8.

Thanks in Advance
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We won't be able to help without seeing your code so first thing to do is post the relevant bits here.

Also, what steps did you take to make your code thread safe? If your code is not thread safe then its behavior will be undefined.

Finally, it is not a good design to use static variables for thread communication. There will be better ways for doing what you need to do.
 
Tapan Agarwal
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike...Thanks for clarification...Using static variable was indeed not a better way to go....I removed the static variable and used join instead....its working fine now.

Thanks for the help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!