Ok so i have implemented a program that simulates a post offie, but now i cant figure out why my threads arnt join and printing, also not sure why my threads are not interleaving. Anyone care to take a look at my code?, its kinda long thats why i dint post it.

You should post a SSCCE. It not only makes it easy for people to help you; it is also a powerful step toward solving your problem yourself. In preparing your SSCCE, you may find that you don't really need help.

Threads can be tricky. You can rarely depend on them for anything. The best place to discover exactly what you can depend on is the Java Language Specification for threads: http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html

When it comes to interleaving of threads, you should remember Item 72 of Effective Java Second Edition: "Don't depend on the thread scheduler." It sounds like you are hoping that your threads will toss the processor back and forth like a hot potato. If that is what you mean by interleaving, then remember Item 72 and force it to happen instead of depending on the thread scheduler to make it happen. Always assume that the thread you least want to be running will be the one chosen by the scheduler; the only way you can stop it from happening is by putting that thread to sleep, such as with Thread.sleep, Object.wait, or by forcing it to wait to enter a synchronized block. A well-behaved thread will stop frequently so that other threads get a chance to run even when the scheduler is doing its best to prevent it. Also, don't expect Thread.yield to help because all that does is suggest that the scheduler consider choosing another thread to run, which is very little help when the scheduler always chooses the wrong thread.

Edited 3 Years Ago by bguild

This question has already been answered. Start a new discussion instead.