Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Thank you , i think this usage of loops is awesome. I never thought about it this way . Had to take a step back to look at my code! so awesome! Commented Mar 30, 2014 at 19:56
  • 1
    This solves a problem in the original code but is not the proper way to wait for threads to complete. There's almost always a better approach than calling Thread.sleep, whatever the problem. See the invokeAll answer below. Commented Mar 30, 2014 at 20:12
  • But i do need it to sleep right? invokeall would let me know if all threads are finished but after that i still need to use thread sleep. So is the above given approach still not right? Commented Mar 31, 2014 at 5:26
  • 1
    Put a check for outer while loop also. If jobStack is empty then come out of outer while loop as simple as it is. Commented Mar 31, 2014 at 5:27
  • exactly what i did now :) Commented Mar 31, 2014 at 7:30