File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes thread synchronization query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "thread synchronization query" Watch "thread synchronization query" New topic

thread synchronization query

Abhishek Purwar
Ranch Hand

Joined: Dec 15, 2007
Posts: 63


I have query for thread synchronization.

Suppose there are three threads and there is one method which takes number as input and prints number.
If threads passes same number, number should print one time and if different numbers provided as input then all different number should print.

For e.g.
If thread1 and thread2 passes 1 as input to method and thread 3 passes 2 as input then 1 should print once and 2 should print once.
If thread 1 passes 1, thread 2 passes 2 and thread 3 passes 3 then all number should get printed as all are different.

Please suggest me how I shall achieve this.


Abhishek Purwar,
Jelle Klap

Joined: Mar 10, 2008
Posts: 1951

How would you approach it and why? Think about it for a bit and then try coming up with an SSCCE you can post here.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
I agree. Here's the link:
subject: thread synchronization query
It's not a secret anymore!