Archive for December, 2011

Question by Alex: Using semaphores in Java? How can I make threads run at different frequencies to one another?
I have three different threads running in my Java program. One prints “1″, another “2″, and the last “3″. I need to make the “1″s and “2″s print less frequently than the “3″, using semaphores, but I’m very stuck. Any ideas?

Best answer:

Answer by McFate
You could wait on one semaphone between all three threads, and then:

(1) Print “3″ every time you get the semaphore in the “3″ thread
(2) Print “1″ only every second or third time you get the semaphore in the “1″ thread

Add your own answer in the comments!

Effective Java: Programming Language Guide (Java Series)

(Pearson Education) Working solutions to programming challenges faced by Java developers on a daily basis, revealing what to do to produce clear, robust and efficient code. Include rules in short essay form, and the author’s ‘war stories,’ giving advice and insights into nuances of the language. Softcover. Written for the working Java developer, Joshua Bloch’s Effective Java Programming Language Guide provides a truly useful set of over 50 best practices and tips for writing better Java

List Price: $ 54.99

Price: $ 17.70

Murach’s Java Programming

Murach’s Java Programming

Developers often tell me they wish they’d found our Java book first, before spending time and money on others. Here are a few of the reasons why I believe this book will work equally well for you:
• This book teaches the core Java skills that you need to work with objects, graphical user interfaces (GUIs), files, and databases.
• It gives you a fast start! In fact, by the end of chapter 6, you’ll be developing bulletproof Java applications with business classes and objects.
• I

List Price: $ 57.50

Price: $ 36.00