Showing posts with label threads. Show all posts
Showing posts with label threads. Show all posts

Friday, December 5, 2008

New section: using threads in Java

The first articles in this new section look primarily at how to use "raw" threads in Java. As well as the basics such as how to create a thread and stop or interrupt it, the section looks at more advanced threading topics such as:

How threads work

A look at threads "under the hood": an examination of some of the details of thread scheduling, and the implications of different scheduling algorithms for Java threads and the methods that control them.

Thread priorities

How they work (or rather, how they don't work...) on specific operating systems. Did you know, for example:
  • on Linux, setPriority() has no effect pre Java 6, and that even then you need to run as rootand use a special command-line flag?
  • on Windows, the implementation of setPriority() changed between Sun's Java 5 and Java 6 implementations?
  • on Windows, thread priorities have little effect on threads competing for CPU?
See the article for more information.

sleep() and yield()

Information on the limitations and behaviour of sleep() under different load, sleep granularity, and bugs in the Windows implementation. And finally, find out what yield() actually does...!

Suggestions welcome!


As with all sections of the Javamex site, suggestions are very welcome here for new topics or specific questions you'd like to see answered. Updates and additions will be added periodically. Corrections are also very welcome since, particularly in the case of the some of the threading topics, I have tried to pull together information which is elusive or described in contradictory ways in different sources!

Sunday, July 6, 2008

The wait/notify mechanism in Java

One of the most commonly viewed articles on the Javamex site is our discussion of the wait/notify mechanism. It appears that this is a particular topic of doubt among developers.

The wait/notify mechanism is essentially used for one thread to "signal" or pass information to another thread. As of Java 5, the new concurrency classes provide more convenient alternatives to many common uses of wait() and notify(). See in particular:
Suggested additions to these discussions are welcome (on this blog), as well as feedback on how well these articles helped you solve your problem.