• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Threads not closing

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I was born with webbed fish toes. This tiny ad is my only friend:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic