This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
(PLEASE answer in "little java words" for I am learning. <Very big smile)
In my main server thread it contains a queue (of out going packets) and a client ref hashmap with id's and the ref to each new client OBJ I create. Also, this same server generates a thread which handles the packets queue which then is distributed to the hashmaps (client ref).queues (probably more info then is needed for this question.)
Any who, I need my server dispatch thread to walk the client ref hashmap and plug in the packets into each client's queue.. this same hashmap is is added to each time a client connects.. (So I'm seeing a need to syncronize)
In the main server thread syncronizing the read and write methods to the hashmap is not how I want to do this right?
Somehow which I'm not sure of I need to syncronize my queue's and hashmap.
Anyone have a good article or some code snipets to explain how to do this.
Man I was so pleased with myself How well I was creating threads and having them work sending packets back and forth to my client. Then I started thinking....
P.S. I created a 1 does all method for my queues that I think is safe code listed below...
1. hashmap is not synchronized so it must be operated in single thread environment.
2. if you want to use hashmap with more than one thread consider using synchronized hashmap or Concurrent hashmap.
3. you can get synchronized hashmap by calling Collections.synchronizedMap() method.