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!

Related posts:

  1. How does Java make its decision when allocating time slices to Threads?
  2. In Java: How can I make a Timer based repaint, instead repaint as fast as the processor can handle?
  3. FAQ: How to make a Java application display a file chooser and allow users to choose a file ?
  4. How do I make java moss blanket the bottom of my fishtank?
  5. JAVA: How can I make two pieces of software communicate over a network?